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

◆ exp2_fp()

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

Definition at line 236 of file u8x24.h.

236 {
237 u8x24 fl_val = floor(x);
238 u8x24 fr = x - fl_val;
239 u32 n = fl_val.mValue >> FRAC_BITS;
240
241 // Prevent overflow
242 if (n >= INT_BITS) return from_raw(0xFFFFFFFFu);
243
244 u32 int_pow = static_cast<u32>(SCALE) << n;
245
246 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
247 constexpr int IFRAC = 24;
248 constexpr u64 d0 = 11629376ULL; // 0.69316 * 2^24
249 constexpr u64 d1 = 4038400ULL; // 0.24071 * 2^24
250 constexpr u64 d2 = 895232ULL; // 0.05336 * 2^24
251 constexpr u64 d3 = 214016ULL; // 0.01276 * 2^24
252
253 u64 fr24 = static_cast<u64>(fr.mValue);
254 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
255 u64 acc = d3;
256 acc = d2 + ((acc * fr24) >> IFRAC);
257 acc = d1 + ((acc * fr24) >> IFRAC);
258 acc = d0 + ((acc * fr24) >> IFRAC);
259 constexpr u64 one24 = 1ULL << IFRAC;
260 u64 frac_pow24 = one24 + ((acc * fr24) >> IFRAC);
261
262 // Scale by int_pow (result stays at 24 frac bits).
263 u64 result = (static_cast<u64>(int_pow) * frac_pow24) >> FRAC_BITS;
264 return from_raw(static_cast<u32>(result));
265 }
static constexpr FASTLED_FORCE_INLINE u8x24 from_raw(u32 raw) FL_NOEXCEPT
Definition u8x24.h:53
static constexpr int FRAC_BITS
Definition u8x24.h:22
static constexpr int INT_BITS
Definition u8x24.h:21
constexpr u8x24() FL_NOEXCEPT=default
static constexpr i32 SCALE
Definition u8x24.h:23
static constexpr FASTLED_FORCE_INLINE u8x24 floor(u8x24 x) FL_NOEXCEPT
Definition u8x24.h:116
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
fl::u64 u64
Definition s16x16x4.h:221

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