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

◆ log2_fp()

static FASTLED_FORCE_INLINE s8x24 fl::s8x24::log2_fp ( s8x24 x)
inlinestaticprivate

Definition at line 319 of file s8x24.h.

319 {
320 u32 val = static_cast<u32>(x.mValue);
321 int msb = highest_bit(val);
322 i32 int_part = msb - FRAC_BITS;
323 i32 t;
324 if (msb >= FRAC_BITS) {
325 t = static_cast<i32>(
326 (val >> (msb - FRAC_BITS)) - (SCALE));
327 } else {
328 t = static_cast<i32>(
329 (val << (FRAC_BITS - msb)) - (SCALE));
330 }
331 // 4-term minimax coefficients for log2(1+t), t in [0,1).
332 // Stored as i64 with 24 fractional bits (same as FRAC_BITS).
333 constexpr int IFRAC = 24;
334 constexpr i64 c0 = 24189248LL; // 1.44179 * 2^24
335 constexpr i64 c1 = -11728384LL; // -0.69907 * 2^24
336 constexpr i64 c2 = 6098176LL; // 0.36348 * 2^24
337 constexpr i64 c3 = -1788416LL; // -0.10660 * 2^24
338 // t is already at 24 frac bits (same as FRAC_BITS).
339 i64 t24 = static_cast<i64>(t);
340 // Horner: t * (c0 + t * (c1 + t * (c2 + t * c3)))
341 i64 acc = c3;
342 acc = c2 + ((acc * t24) >> IFRAC);
343 acc = c1 + ((acc * t24) >> IFRAC);
344 acc = c0 + ((acc * t24) >> IFRAC);
345 i64 frac_part = (acc * t24) >> IFRAC;
346 i32 frac24 = static_cast<i32>(frac_part);
347 return from_raw(static_cast<i32>(static_cast<u32>(int_part) << FRAC_BITS) + frac24);
348 }
static constexpr i32 SCALE
Definition s8x24.h:23
static constexpr FASTLED_FORCE_INLINE s8x24 from_raw(i32 raw) FL_NOEXCEPT
Definition s8x24.h:53
static constexpr int FRAC_BITS
Definition s8x24.h:22
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v) FL_NOEXCEPT
Definition s8x24.h:302
fl::i64 i64
Definition s16x16x4.h:222

References s8x24(), FASTLED_FORCE_INLINE, FL_NOEXCEPT, FRAC_BITS, from_raw(), highest_bit(), SCALE, fl::t, and fl::x.

Referenced by pow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: