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

◆ log2_fp()

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

Definition at line 208 of file u24x8.h.

208 {
209 u32 val = x.mValue;
210 int msb = highest_bit(val);
211 if (msb < 0) return u24x8(); // log2(0) = undefined, return 0
212
213 u32 int_part = msb - FRAC_BITS;
214 u32 t;
215 if (msb >= FRAC_BITS) {
216 t = (val >> (msb - FRAC_BITS)) - (SCALE);
217 } else {
218 t = (val << (FRAC_BITS - msb)) - (SCALE);
219 }
220
221 // Simplified 2-term minimax coefficients for log2(1+t), t in [0,1).
222 // Stored as u64 with 16 fractional bits.
223 constexpr int IFRAC = 16;
224 constexpr u64 c0 = 94528ULL; // 1.44179 * 2^16
225 constexpr u64 c1 = 19727ULL; // 0.30093 * 2^16 (unsigned approximation)
226
227 // Extend t from 8 to 16 frac bits.
228 u64 t16 = static_cast<u64>(t) << (IFRAC - FRAC_BITS);
229
230 // Horner for unsigned: simplified polynomial
231 u64 acc = c0 + ((c1 * t16) >> IFRAC);
232 u64 frac_part = (acc * t16) >> IFRAC;
233
234 // Convert from 16 frac bits back to 8.
235 u32 frac8 = static_cast<u32>(frac_part >> (IFRAC - FRAC_BITS));
236 return from_raw((int_part << FRAC_BITS) + frac8);
237 }
static constexpr FASTLED_FORCE_INLINE u24x8 from_raw(u32 raw) FL_NOEXCEPT
Definition u24x8.h:52
constexpr u24x8() FL_NOEXCEPT=default
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v) FL_NOEXCEPT
Definition u24x8.h:191
static constexpr i32 SCALE
Definition u24x8.h:22
static constexpr int FRAC_BITS
Definition u24x8.h:21
fl::u64 u64
Definition s16x16x4.h:221

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