mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
math: fast aprox cos and sin
This commit is contained in:
parent
5c598a3085
commit
ed55778d2a
@ -320,3 +320,28 @@ pub fn trunc(a f64) f64 {
|
|||||||
return C.trunc(a)
|
return C.trunc(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Faster approximate sin() and cos() implemented from lolremez
|
||||||
|
pub fn aprox_sin(a f64) f64 {
|
||||||
|
a0 := 1.91059300966915117e-31
|
||||||
|
a1 := 1.00086760103908896
|
||||||
|
a2 := -1.21276126894734565e-2
|
||||||
|
a3 := -1.38078780785773762e-1
|
||||||
|
a4 := -2.67353392911981221e-2
|
||||||
|
a5 := 2.08026600266304389e-2
|
||||||
|
a6 := -3.03996055049204407e-3
|
||||||
|
a7 := 1.38235642404333740e-4
|
||||||
|
return a0 + a * (a1 + a * (a2 + a * (a3 + a * (a4 + a * (a5 + a * (a6 + a * a7))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn aprox_cos(a f64) f64 {
|
||||||
|
a0 := 9.9995999154986614e-1
|
||||||
|
a1 := 1.2548995793001028e-3
|
||||||
|
a2 := -5.0648546280678015e-1
|
||||||
|
a3 := 1.2942246466519995e-2
|
||||||
|
a4 := 2.8668384702547972e-2
|
||||||
|
a5 := 7.3726485210586547e-3
|
||||||
|
a6 := -3.8510875386947414e-3
|
||||||
|
a7 := 4.7196604604366623e-4
|
||||||
|
a8 := -1.8776444013090451e-5
|
||||||
|
return a0 + a * (a1 + a * (a2 + a * (a3 + a * (a4 + a * (a5 + a * (a6 + a * (a7 + a * a8)))))))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user