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

◆ exp2_fp()

static FASTLED_FORCE_INLINE u24x8 fl::u24x8::exp2_fp ( u24x8 x)
inlinestaticprivate

Definition at line 242 of file u24x8.h.

242 {
243 u24x8 fl_val = floor(x);
244 u24x8 fr = x - fl_val;
245 u32 n = fl_val.mValue >> FRAC_BITS;
246 if (n >= INT_BITS) return from_raw(0xFFFFFFFF);
247 u32 int_pow;
248 int_pow = static_cast<u32>(SCALE) << n;
249 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
250 // Stored as u64 with 16 fractional bits.
251 constexpr int IFRAC = 16;
252 constexpr u64 d0 = 45427ULL; // 0.69316 * 2^16
253 constexpr u64 d1 = 15775ULL; // 0.24071 * 2^16
254 constexpr u64 d2 = 3497ULL; // 0.05336 * 2^16
255 constexpr u64 d3 = 836ULL; // 0.01276 * 2^16
256 // Extend fr from 8 to 16 frac bits.
257 u64 fr16 = static_cast<u64>(fr.mValue) << (IFRAC - FRAC_BITS);
258 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
259 u64 acc = d3;
260 acc = d2 + ((acc * fr16) >> IFRAC);
261 acc = d1 + ((acc * fr16) >> IFRAC);
262 acc = d0 + ((acc * fr16) >> IFRAC);
263 constexpr u64 one16 = 1ULL << IFRAC;
264 u64 frac_pow16 = one16 + ((acc * fr16) >> IFRAC);
265 // Convert from 16 frac bits to 8 frac bits, then scale by int_pow.
266 u32 frac_pow8 = static_cast<u32>(frac_pow16 >> (IFRAC - FRAC_BITS));
267 u64 result =
268 (static_cast<u64>(int_pow) * frac_pow8) >> FRAC_BITS;
269 return from_raw(static_cast<u32>(result));
270 }
static constexpr int INT_BITS
Definition u24x8.h:20
static constexpr FASTLED_FORCE_INLINE u24x8 from_raw(u32 raw) FL_NOEXCEPT
Definition u24x8.h:52
constexpr u24x8() FL_NOEXCEPT=default
static constexpr FASTLED_FORCE_INLINE u24x8 floor(u24x8 x) FL_NOEXCEPT
Definition u24x8.h:115
static constexpr i32 SCALE
Definition u24x8.h:22
static constexpr int FRAC_BITS
Definition u24x8.h:21
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
fl::u64 u64
Definition s16x16x4.h:221

References u24x8(), FASTLED_FORCE_INLINE, FL_NOEXCEPT, floor(), FRAC_BITS, from_raw(), INT_BITS, mValue, SCALE, and fl::x.

Referenced by pow().

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