MCPcopy Create free account
hub / github.com/FastLED/FastLED / sin_reduce_

Function sin_reduce_

src/fl/math/math.cpp.hpp:184–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182
183template <typename F>
184inline 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
201template <typename F>
202inline F cos_reduce_(F x) FL_NOEXCEPT {

Callers 1

cos_reduce_Function · 0.85

Calls 2

FClass · 0.85
sin_poly_quarterturn_Function · 0.85

Tested by

no test coverage detected