]> Cypherpunks repositories - gostls13.git/commitdiff
math: use Sincos instead of Sin and Cos in Jn and Yn
authorNeven Sajko <nsajko@gmail.com>
Mon, 25 Mar 2019 22:40:27 +0000 (22:40 +0000)
committerRobert Griesemer <gri@golang.org>
Mon, 25 Mar 2019 22:41:37 +0000 (22:41 +0000)
Change-Id: I0da3857013f1d4e90820fb043314d78924113a27
GitHub-Last-Rev: 7c3d813c6e188a4afda54b736db14370e52b6f94
GitHub-Pull-Request: golang/go#31019
Reviewed-on: https://go-review.googlesource.com/c/go/+/169078
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/jn.go

index 4a8ddfad9bd80a7055cb9d86ee430b09b50c22d5..b1aca8ff6be74722ea1e76349f6f2470626c307f 100644 (file)
@@ -103,15 +103,15 @@ func Jn(n int, x float64) float64 {
                        //                 3     s+c             c-s
 
                        var temp float64
-                       switch n & 3 {
+                       switch s, c := Sincos(x); n & 3 {
                        case 0:
-                               temp = Cos(x) + Sin(x)
+                               temp = c + s
                        case 1:
-                               temp = -Cos(x) + Sin(x)
+                               temp = -c + s
                        case 2:
-                               temp = -Cos(x) - Sin(x)
+                               temp = -c - s
                        case 3:
-                               temp = Cos(x) - Sin(x)
+                               temp = c - s
                        }
                        b = (1 / SqrtPi) * temp / Sqrt(x)
                } else {
@@ -278,15 +278,15 @@ func Yn(n int, x float64) float64 {
                //                 3     s+c             c-s
 
                var temp float64
-               switch n & 3 {
+               switch s, c := Sincos(x); n & 3 {
                case 0:
-                       temp = Sin(x) - Cos(x)
+                       temp = s - c
                case 1:
-                       temp = -Sin(x) - Cos(x)
+                       temp = -s - c
                case 2:
-                       temp = -Sin(x) + Cos(x)
+                       temp = -s + c
                case 3:
-                       temp = Sin(x) + Cos(x)
+                       temp = s + c
                }
                b = (1 / SqrtPi) * temp / Sqrt(x)
        } else {