Help, My Sin Is Slow and My FPU is Inaccurate - Bert Hubert's writings
a day ago
- The author encountered a mysterious slowdown in sin() when computing exact multiples of π, which triggered glibc's slow path.
- FPU hardware instructions for trigonometry are inaccurate for large inputs due to the difficulty of range reduction.
- The Payne-Hanek-Corbett algorithm (1983) solved accurate range reduction for large angles in software.
- The slowdown occurred because the code computed sin(2π * Hz * t) with integer steps, producing exact multiples of π.
- As of 2021, glibc's libm has been optimized (patch by Wilco Dijkstra) eliminating the drastic slowdown for such inputs.