1
0
mirror of https://github.com/golang/go synced 2024-11-12 07:10:22 -07:00

math: use Sincos instead of Sin and Cos in Jn and Yn

This should be slightly faster.

Benchmarks:

name  old time/op  new time/op  delta
Jn-8   108ns ± 0%   109ns ± 0%  +0.93%  (p=0.000 n=20+16)
Yn-8   106ns ± 0%   106ns ± 0%    ~     (all equal)
This commit is contained in:
Neven Sajko 2019-03-25 01:47:59 +00:00
parent 501632339f
commit 7c3d813c6e

View 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 {