Skip to main content

sin_cos_turns

Function sin_cos_turns 

Source
pub fn sin_cos_turns(u: f64) -> (f64, f64)
Expand description

(sin, cos) of the angle 2 pi u for u in [0, 1), the azimuth of a collision drawn as a fraction of a turn.

The azimuth is the one transcendental call left per collision that the geometry of the scattering does not remove, and the platform sin and cos are two separate library calls. This does the same with exact argument reduction and short Maclaurin series: x = 4u is split as the nearest integer number of quarter turns k plus a remainder, so the series argument r = (x - k) pi / 2 lies in [-pi/4, pi/4], where the series through r^17 (sine) and r^18 (cosine) have truncation error below 1e-19 (the first omitted terms, r^19 / 19! and r^20 / 20!). The quarter turn k then rotates (sin r, cos r) into place. Results agree with the library sin_cos to about 2e-16 and are the same on every platform, because only IEEE multiplications and additions are used.