blooblib/math.go

25 lines
520 B
Go

package bloob
import "math"
func FastSin(x float64) float64 {
const PI = 3.14159265358979323846264338327950288
const INVPI = 0.31830988618379067153776752674502872
const A = 0.00735246819687011731341356165096815
const B = -0.16528911397014738207016302002888890
const C = 0.99969198629596757779830113868360584
k := int32(math.Round(INVPI * x))
x -= float64(k) * PI
x2 := x * x
x = x * (C + x2*(B+A*x2))
if k%2 != 0 {
x = -x
}
return x
}
func FastCos(x float64) float64 {
return FastSin(x + math.Pi/2)
}