FastLED 3.10.8
Loading...
Searching...
No Matches

◆ exp_reduced_() [1/2]

double fl::detail::exp_reduced_ ( double x)
inline

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

156 {
157 // AVR builds double as 32 bits: the float path is the double path there,
158 // and the 64-bit bit patterns below would read past the value.
159 if (sizeof(double) == sizeof(float)) {
160 return static_cast<double>(exp_reduced_(static_cast<float>(x)));
161 }
162 DoubleBits xb;
163 xb.f = x;
164 const u64 ax = xb.u & 0x7fffffffffffffffull;
165 if (ax >= 0x40862e42fefa39efull) { // |x| >= 709.7827, or NaN
166 if (ax > 0x7ff0000000000000ull) return x; // NaN
167 if ((xb.u >> 63) == 0u) { // overflow -> +inf
168 DoubleBits inf;
169 inf.u = 0x7ff0000000000000ull;
170 return inf.f;
171 }
172 if (ax >= 0x40874910d52d3052ull) return 0.0; // x <= -745.133: underflow
173 }
174 const double kMagic = 6755399441055744.0; // 1.5 * 2^52
176 t.f = x * 1.44269504088896338700e+00 + kMagic;
177 const int k = static_cast<int>(t.i - 0x4338000000000000ll);
178 const double kd = t.f - kMagic;
179 // fdlibm e_exp: e^r = 1 + 2r/(2 - c(r)) with c a degree-5 polynomial in
180 // r^2. Five multiply-adds and one division reach < 1 ulp, half the work of
181 // a Taylor series of the same accuracy; that matters on cores that do
182 // double in software.
183 const double hi = x - kd * 6.93147180369123816490e-01;
184 const double lo = kd * 1.90821492927058770002e-10;
185 const double r = hi - lo;
186 const double r2 = r * r;
187 const double c = r - r2 * (1.66666666666666019037e-01 +
188 r2 * (-2.77777777770155933842e-03 +
189 r2 * (6.61375632143793436117e-05 +
190 r2 * (-1.65339022054652515390e-06 +
191 r2 * 4.13813679705723846039e-08))));
192 const double p = 1.0 - ((lo - (r * c) / (2.0 - c)) - hi);
193 return scale_pow2_(p, k);
194}
float scale_pow2_(float p, int k) FL_NO_EXCEPT
Definition math.cpp.hpp:107
float exp_reduced_(float x) FL_NO_EXCEPT
Definition math.cpp.hpp:125
fl::u64 u64
Definition stdint.h:220

References exp_reduced_(), fl::detail::DoubleBits::f, fl::FL_NO_EXCEPT, scale_pow2_(), fl::t, fl::detail::DoubleBits::u, and fl::x.

+ Here is the call graph for this function: