FastLED 3.10.6
Loading...
Searching...
No Matches

◆ sin_reduce_()

template<typename F>
F fl::detail::sin_reduce_ ( F x)
inline

Definition at line 265 of file math.cpp.hpp.

265 {
266 const F kPi = F(3.14159265358979323846);
267 const F kTwoPi = F(6.28318530717958647692);
268 const F kPiHalf = F(1.57079632679489661923);
269 // Reduce to [-π, π]: subtract floor(x / 2π) * 2π.
270 // For the FastLED use cases we expect |x| < ~100, so this loop runs a
271 // bounded number of times. For pathological inputs we cap iterations.
272 int guard = 32;
273 while (x > kPi && guard > 0) { x -= kTwoPi; --guard; }
274 while (x < -kPi && guard > 0) { x += kTwoPi; --guard; }
275 // Map to [-π/2, π/2] using sin(π - x) = sin(x).
276 if (x > kPiHalf) x = kPi - x;
277 if (x < -kPiHalf) x = -kPi - x;
278 // [-π/2, π/2] -- the polynomial works fine here (max |x| ≈ 1.57).
279 return sin_poly_quarterturn_(x);
280}
int x
Definition simple.h:92
F sin_poly_quarterturn_(F x) FL_NO_EXCEPT
Definition math.cpp.hpp:251

References fl::FL_NO_EXCEPT, sin_poly_quarterturn_(), and fl::x.

Referenced by cos_reduce_(), fl::sin_impl_double(), fl::sin_impl_float(), fl::tan_impl_double(), and fl::tan_impl_float().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: