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

◆ log2_fp()

template<typename Derived, int IntBits, int FracBits>
static FASTLED_FORCE_INLINE Derived fl::fixed_point_base< Derived, IntBits, FracBits >::log2_fp ( Derived x)
inlinestaticprivate

Definition at line 344 of file base.h.

344 {
345 constexpr int IFRAC = traits::IFRAC;
346
348 int msb = highest_bit(static_cast<u32>(val));
350 raw_type t;
351 if (msb >= FRAC_BITS) {
352 t = static_cast<raw_type>(
353 (val >> (msb - FRAC_BITS)) - (static_cast<unsigned_raw_type>(1) << FRAC_BITS));
354 } else {
355 t = static_cast<raw_type>(
356 (val << (FRAC_BITS - msb)) - (static_cast<unsigned_raw_type>(1) << FRAC_BITS));
357 }
358
359 // 4-term minimax coefficients for log2(1+t), t in [0,1).
360 // Coefficients scaled by 2^IFRAC.
361 // Use poly_intermediate_type (i32 or i64 based on IFRAC).
363 constexpr poly_type c0 = static_cast<poly_type>(1.44179 * (1LL << IFRAC));
364 constexpr poly_type c1 = static_cast<poly_type>(-0.69907 * (1LL << IFRAC));
365 constexpr poly_type c2 = static_cast<poly_type>(0.36348 * (1LL << IFRAC));
366 constexpr poly_type c3 = static_cast<poly_type>(-0.10660 * (1LL << IFRAC));
367
368 // Extend t to IFRAC fractional bits
369 poly_type t_ifrac = static_cast<poly_type>(t) << (IFRAC - FRAC_BITS);
370
371 // Horner: t * (c0 + t * (c1 + t * (c2 + t * c3)))
372 return log2_horner(int_part, t_ifrac, c0, c1, c2, c3, fl::bool_constant<(IFRAC <= 16)>());
373 }
typename traits::unsigned_raw_type unsigned_raw_type
Definition base.h:32
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v)
Definition base.h:327
static FASTLED_FORCE_INLINE Derived log2_horner(raw_type int_part, PolyType t_ifrac, PolyType c0, PolyType c1, PolyType c2, PolyType c3, fl::true_type)
Definition base.h:377
static constexpr int FRAC_BITS
Definition base.h:38
typename traits::raw_type raw_type
Definition base.h:31
raw_type mValue
Definition base.h:41
typename traits::poly_intermediate_type poly_intermediate_type
Definition base.h:35
static constexpr int IFRAC
Definition traits.h:120

References FASTLED_FORCE_INLINE, FRAC_BITS, highest_bit(), fl::fixed_point_traits< IntBits, FracBits >::IFRAC, log2_horner(), fl::t, and fl::x.

Referenced by pow().

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