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

◆ exp2_fp()

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

Definition at line 255 of file u16x16.h.

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

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