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

◆ log2_fp()

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

Definition at line 202 of file u8x24.h.

202 {
203 u32 val = x.mValue;
204 int msb = highest_bit(val);
205 if (msb < 0) return u8x24(); // log2(0) = -inf, return 0
206
207 u32 int_part = msb - FRAC_BITS;
208 u32 t;
209 if (msb >= FRAC_BITS) {
210 t = (val >> (msb - FRAC_BITS)) - (SCALE);
211 } else {
212 t = (val << (FRAC_BITS - msb)) - (SCALE);
213 }
214
215 // 4-term minimax coefficients for log2(1+t), t in [0,1).
216 constexpr int IFRAC = 24;
217 constexpr u64 c0 = 24189248ULL; // 1.44179 * 2^24
218 constexpr i64 c1 = -11728384LL; // -0.69907 * 2^24
219 constexpr i64 c2 = 6098176LL; // 0.36348 * 2^24
220 constexpr i64 c3 = -1788416LL; // -0.10660 * 2^24
221
222 i64 t24 = static_cast<i64>(t);
223 // Horner: t * (c0 + t * (c1 + t * (c2 + t * c3)))
224 i64 acc = c3;
225 acc = c2 + ((acc * t24) >> IFRAC);
226 acc = c1 + ((acc * t24) >> IFRAC);
227 acc = static_cast<i64>(c0) + ((acc * t24) >> IFRAC);
228 i64 frac_part = (acc * t24) >> IFRAC;
229
230 // Combine integer and fractional parts
231 i64 result = (static_cast<i64>(int_part) << FRAC_BITS) + frac_part;
232 return from_raw(result >= 0 ? static_cast<u32>(result) : 0);
233 }
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
constexpr u8x24() FL_NOEXCEPT=default
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v) FL_NOEXCEPT
Definition u8x24.h:187
static constexpr i32 SCALE
Definition u8x24.h:23
fl::i64 i64
Definition s16x16x4.h:222
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, 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: