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

◆ exp2_fp()

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

Definition at line 357 of file s8x8.h.

357 {
358 s8x8 fl_val = floor(x);
359 s8x8 fr = x - fl_val;
360 i32 n = fl_val.mValue >> FRAC_BITS;
361 if (n >= INT_BITS - 1) return from_raw(0x7FFF);
362 if (n < -FRAC_BITS) return s8x8();
363 i32 int_pow;
364 if (n >= 0) {
365 int_pow = static_cast<i32>(SCALE) << n;
366 } else {
367 int_pow = static_cast<i32>(SCALE) >> (-n);
368 }
369 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
370 // Stored as i32 with 16 fractional bits.
371 constexpr int IFRAC = 16;
372 constexpr i32 d0 = 45427; // 0.69316 * 2^16
373 constexpr i32 d1 = 15775; // 0.24071 * 2^16
374 constexpr i32 d2 = 3497; // 0.05336 * 2^16
375 constexpr i32 d3 = 836; // 0.01276 * 2^16
376 // Extend fr from 8 to 16 frac bits.
377 i32 fr16 = static_cast<i32>(fr.mValue) << (IFRAC - FRAC_BITS);
378 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
379 i32 acc = d3;
380 acc = d2 + static_cast<i32>((static_cast<i64>(acc) * fr16) >> IFRAC);
381 acc = d1 + static_cast<i32>((static_cast<i64>(acc) * fr16) >> IFRAC);
382 acc = d0 + static_cast<i32>((static_cast<i64>(acc) * fr16) >> IFRAC);
383 constexpr i32 one16 = static_cast<i32>(1) << IFRAC;
384 i32 frac_pow16 = one16 + static_cast<i32>((static_cast<i64>(acc) * fr16) >> IFRAC);
385 // Convert from 16 frac bits to 8 frac bits, then scale by int_pow.
386 i32 frac_pow8 = frac_pow16 >> (IFRAC - FRAC_BITS);
387 i32 result =
388 (int_pow * frac_pow8) >> FRAC_BITS;
389 return from_raw(static_cast<i16>(result));
390 }
constexpr s8x8() FL_NOEXCEPT=default
constexpr FASTLED_FORCE_INLINE s8x8 floor() const FL_NOEXCEPT
Definition s8x8.h:234
static constexpr int FRAC_BITS
Definition s8x8.h:22
static constexpr FASTLED_FORCE_INLINE s8x8 from_raw(i16 raw) FL_NOEXCEPT
Definition s8x8.h:53
static constexpr int INT_BITS
Definition s8x8.h:21
static constexpr i32 SCALE
Definition s8x8.h:23
fl::i64 i64
Definition s16x16x4.h:222
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

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