FastLED 3.9.15
Loading...
Searching...
No Matches

◆ sin_reduce_()

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

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

184 {
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}
int x
Definition simple.h:92
F sin_poly_quarterturn_(F x) FL_NOEXCEPT
Definition math.cpp.hpp:170

References FL_NOEXCEPT, 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: