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

◆ exp2_fp()

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

Definition at line 244 of file u4x12.h.

244 {
245 u4x12 fl_val = floor(x);
246 u4x12 fr = x - fl_val;
247 i32 n = fl_val.mValue >> FRAC_BITS;
248 if (n >= INT_BITS) return from_raw(0xFFFF);
249 if (n < 0) return u4x12();
250 u32 int_pow = static_cast<u32>(SCALE) << n;
251 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
252 // Stored as i32 with 20 fractional bits.
253 constexpr int IFRAC = 20;
254 constexpr i32 d0 = 726836; // 0.69316 * 2^20
255 constexpr i32 d1 = 252400; // 0.24071 * 2^20
256 constexpr i32 d2 = 55952; // 0.05336 * 2^20
257 constexpr i32 d3 = 13376; // 0.01276 * 2^20
258 // Extend fr from 12 to 20 frac bits.
259 i32 fr20 = static_cast<i32>(fr.mValue) << (IFRAC - FRAC_BITS);
260 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
261 i32 acc = d3;
262 acc = d2 + static_cast<i32>((static_cast<i64>(acc) * fr20) >> IFRAC);
263 acc = d1 + static_cast<i32>((static_cast<i64>(acc) * fr20) >> IFRAC);
264 acc = d0 + static_cast<i32>((static_cast<i64>(acc) * fr20) >> IFRAC);
265 constexpr i32 one20 = static_cast<i32>(1) << IFRAC;
266 i32 frac_pow20 = one20 + static_cast<i32>((static_cast<i64>(acc) * fr20) >> IFRAC);
267 // Convert from 20 frac bits to 12 frac bits, then scale by int_pow.
268 u32 frac_pow12 = static_cast<u32>(frac_pow20) >> (IFRAC - FRAC_BITS);
269 u32 result =
270 (int_pow * frac_pow12) >> FRAC_BITS;
271 return from_raw(static_cast<u16>(result));
272 }
static constexpr int INT_BITS
Definition u4x12.h:20
static constexpr i32 SCALE
Definition u4x12.h:22
static constexpr int FRAC_BITS
Definition u4x12.h:21
static constexpr FASTLED_FORCE_INLINE u4x12 from_raw(u16 raw) FL_NOEXCEPT
Definition u4x12.h:52
static constexpr FASTLED_FORCE_INLINE u4x12 floor(u4x12 x) FL_NOEXCEPT
Definition u4x12.h:115
constexpr u4x12() FL_NOEXCEPT=default
fl::i64 i64
Definition s16x16x4.h:222
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

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