FastLED 3.10.8
Loading...
Searching...
No Matches

◆ exp2_fp()

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

Definition at line 264 of file u16x16.h.

264 {
265 u16x16 fl_val = floor(x);
266 u16x16 fr = x - fl_val;
267 u32 n = fl_val.mValue >> FRAC_BITS;
268
269 if (n >= INT_BITS) return from_raw(0xFFFFFFFF); // overflow
270
271 u32 int_pow = (SCALE) << n;
272
273 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
274 // Stored as u64 with 24 fractional bits.
275 constexpr int IFRAC = 24;
276 constexpr u64 d0 = 11629376ULL; // 0.69316 * 2^24
277 constexpr u64 d1 = 4038400ULL; // 0.24071 * 2^24
278 constexpr u64 d2 = 895232ULL; // 0.05336 * 2^24
279 constexpr u64 d3 = 214016ULL; // 0.01276 * 2^24
280
281 // Extend fr from 16 to 24 frac bits.
282 u64 fr24 = static_cast<u64>(fr.mValue) << (IFRAC - FRAC_BITS);
283
284 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
285 u64 acc = d3;
286 acc = d2 + ((acc * fr24) >> IFRAC);
287 acc = d1 + ((acc * fr24) >> IFRAC);
288 acc = d0 + ((acc * fr24) >> IFRAC);
289 constexpr u64 one24 = 1ULL << IFRAC;
290 u64 frac_pow24 = one24 + ((acc * fr24) >> IFRAC);
291
292 // Convert from 24 frac bits to 16 frac bits, then scale by int_pow.
293 u32 frac_pow16 = static_cast<u32>(frac_pow24 >> (IFRAC - FRAC_BITS));
294 u64 result = (static_cast<u64>(int_pow) * frac_pow16) >> FRAC_BITS;
295 return from_raw(static_cast<u32>(result));
296 }
static constexpr int INT_BITS
Definition u16x16.h:21
static constexpr FASTLED_FORCE_INLINE u16x16 from_raw(u32 raw) FL_NO_EXCEPT
Definition u16x16.h:54
constexpr u16x16() FL_NO_EXCEPT=default
static constexpr FASTLED_FORCE_INLINE u16x16 floor(u16x16 x) FL_NO_EXCEPT
Definition u16x16.h:138
static constexpr i32 SCALE
Definition u16x16.h:23
static constexpr int FRAC_BITS
Definition u16x16.h:22
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
fl::u64 u64
Definition stdint.h:220

References u16x16(), FASTLED_FORCE_INLINE, fl::FL_NO_EXCEPT, 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: