Skip to content

Commit 270de1c

Browse files
nsajkogriesemer
authored andcommitted
math: use Sincos instead of Sin and Cos in Jn and Yn
Change-Id: I0da3857013f1d4e90820fb043314d78924113a27 GitHub-Last-Rev: 7c3d813 GitHub-Pull-Request: #31019 Reviewed-on: https://go-review.googlesource.com/c/go/+/169078 Reviewed-by: Robert Griesemer <[email protected]>
1 parent e4ba400 commit 270de1c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/math/jn.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ func Jn(n int, x float64) float64 {
103103
// 3 s+c c-s
104104

105105
var temp float64
106-
switch n & 3 {
106+
switch s, c := Sincos(x); n & 3 {
107107
case 0:
108-
temp = Cos(x) + Sin(x)
108+
temp = c + s
109109
case 1:
110-
temp = -Cos(x) + Sin(x)
110+
temp = -c + s
111111
case 2:
112-
temp = -Cos(x) - Sin(x)
112+
temp = -c - s
113113
case 3:
114-
temp = Cos(x) - Sin(x)
114+
temp = c - s
115115
}
116116
b = (1 / SqrtPi) * temp / Sqrt(x)
117117
} else {
@@ -278,15 +278,15 @@ func Yn(n int, x float64) float64 {
278278
// 3 s+c c-s
279279

280280
var temp float64
281-
switch n & 3 {
281+
switch s, c := Sincos(x); n & 3 {
282282
case 0:
283-
temp = Sin(x) - Cos(x)
283+
temp = s - c
284284
case 1:
285-
temp = -Sin(x) - Cos(x)
285+
temp = -s - c
286286
case 2:
287-
temp = -Sin(x) + Cos(x)
287+
temp = -s + c
288288
case 3:
289-
temp = Sin(x) + Cos(x)
289+
temp = s + c
290290
}
291291
b = (1 / SqrtPi) * temp / Sqrt(x)
292292
} else {

0 commit comments

Comments
 (0)