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

◆ log2_fp()

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

Definition at line 230 of file u16x16.h.

230 {
231 u32 val = x.mValue;
232 int msb = highest_bit(val);
233 if (msb < 0) return u16x16(); // log2(0) = undefined, return 0
234
235 u32 int_part = msb - FRAC_BITS;
236 u32 t;
237 if (msb >= FRAC_BITS) {
238 t = (val >> (msb - FRAC_BITS)) - (SCALE);
239 } else {
240 t = (val << (FRAC_BITS - msb)) - (SCALE);
241 }
242
243 // 2-term polynomial coefficients for log2(1+t), t in [0,1).
244 // Stored as u64 with 24 fractional bits.
245 constexpr int IFRAC = 24;
246 constexpr u64 c0 = 24189248ULL; // 1.44179 * 2^24
247 constexpr u64 c1 = 5049984ULL; // 0.30093 * 2^24
248
249 // Extend t from 16 to 24 frac bits.
250 u64 t24 = static_cast<u64>(t) << (IFRAC - FRAC_BITS);
251
252 // Simplified Horner: c0 + c1*t, then multiply by t
253 u64 acc = c0 + ((c1 * t24) >> IFRAC);
254 u64 frac_part = (acc * t24) >> IFRAC;
255
256 // Convert from 24 frac bits back to 16.
257 u32 frac16 = static_cast<u32>(frac_part >> (IFRAC - FRAC_BITS));
258 return from_raw((int_part << FRAC_BITS) + frac16);
259 }
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 int highest_bit(u32 v) FL_NO_EXCEPT
Definition u16x16.h:213
static constexpr i32 SCALE
Definition u16x16.h:23
static constexpr int FRAC_BITS
Definition u16x16.h:22
fl::u64 u64
Definition stdint.h:220

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