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

◆ exp2_fp()

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

Definition at line 356 of file s4x12.h.

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

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