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

◆ exp2_fp()

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

Definition at line 353 of file s8x24.h.

353 {
354 s8x24 fl_val = floor(x);
355 s8x24 fr = x - fl_val;
356 i32 n = fl_val.mValue >> FRAC_BITS;
357 if (n >= INT_BITS - 1) return from_raw(0x7FFFFFFF);
358 if (n < -FRAC_BITS) return s8x24();
359 i32 int_pow;
360 if (n >= 0) {
361 int_pow = static_cast<i32>(SCALE) << n;
362 } else {
363 int_pow = static_cast<i32>(SCALE) >> (-n);
364 }
365 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
366 // Stored as i64 with 24 fractional bits (same as FRAC_BITS).
367 constexpr int IFRAC = 24;
368 constexpr i64 d0 = 11629376LL; // 0.69316 * 2^24
369 constexpr i64 d1 = 4038400LL; // 0.24071 * 2^24
370 constexpr i64 d2 = 895232LL; // 0.05336 * 2^24
371 constexpr i64 d3 = 214016LL; // 0.01276 * 2^24
372 // fr is already at 24 frac bits (same as FRAC_BITS).
373 i64 fr24 = static_cast<i64>(fr.mValue);
374 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
375 i64 acc = d3;
376 acc = d2 + ((acc * fr24) >> IFRAC);
377 acc = d1 + ((acc * fr24) >> IFRAC);
378 acc = d0 + ((acc * fr24) >> IFRAC);
379 constexpr i64 one24 = 1LL << IFRAC;
380 i64 frac_pow24 = one24 + ((acc * fr24) >> IFRAC);
381 // Scale by int_pow (result stays at 24 frac bits).
382 i64 result =
383 (static_cast<i64>(int_pow) * frac_pow24) >> FRAC_BITS;
384 return from_raw(static_cast<i32>(result));
385 }
constexpr FASTLED_FORCE_INLINE s8x24 floor() const FL_NOEXCEPT
Definition s8x24.h:232
static constexpr i32 SCALE
Definition s8x24.h:23
static constexpr int INT_BITS
Definition s8x24.h:21
static constexpr FASTLED_FORCE_INLINE s8x24 from_raw(i32 raw) FL_NOEXCEPT
Definition s8x24.h:53
constexpr s8x24() FL_NOEXCEPT=default
static constexpr int FRAC_BITS
Definition s8x24.h:22
fl::i64 i64
Definition s16x16x4.h:222
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References s8x24(), 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: