| 182 | |
| 183 | template <typename F> |
| 184 | inline F sin_reduce_(F x) FL_NOEXCEPT { |
| 185 | const F kPi = F(3.14159265358979323846); |
| 186 | const F kTwoPi = F(6.28318530717958647692); |
| 187 | const F kPiHalf = F(1.57079632679489661923); |
| 188 | // Reduce to [-π, π]: subtract floor(x / 2π) * 2π. |
| 189 | // For the FastLED use cases we expect |x| < ~100, so this loop runs a |
| 190 | // bounded number of times. For pathological inputs we cap iterations. |
| 191 | int guard = 32; |
| 192 | while (x > kPi && guard > 0) { x -= kTwoPi; --guard; } |
| 193 | while (x < -kPi && guard > 0) { x += kTwoPi; --guard; } |
| 194 | // Map to [-π/2, π/2] using sin(π - x) = sin(x). |
| 195 | if (x > kPiHalf) x = kPi - x; |
| 196 | if (x < -kPiHalf) x = -kPi - x; |
| 197 | // [-π/2, π/2] -- the polynomial works fine here (max |x| ≈ 1.57). |
| 198 | return sin_poly_quarterturn_(x); |
| 199 | } |
| 200 | |
| 201 | template <typename F> |
| 202 | inline F cos_reduce_(F x) FL_NOEXCEPT { |
no test coverage detected