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

◆ exp2_fp()

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

Definition at line 408 of file base.h.

408 {
409 constexpr int IFRAC = traits::IFRAC;
410
412 Derived fr = x - fl_val;
415 if (n < -FRAC_BITS) return Derived();
416
418 if (n >= 0) {
419 int_pow = static_cast<raw_type>(static_cast<unsigned_raw_type>(1) << FRAC_BITS) << n;
420 } else {
421 int_pow = static_cast<raw_type>(static_cast<unsigned_raw_type>(1) << FRAC_BITS) >> (-n);
422 }
423
424 // 4-term minimax coefficients for 2^t - 1, t in [0,1).
425 // Coefficients scaled by 2^IFRAC.
427 constexpr poly_type d0 = static_cast<poly_type>(0.69316 * (1LL << IFRAC));
428 constexpr poly_type d1 = static_cast<poly_type>(0.24071 * (1LL << IFRAC));
429 constexpr poly_type d2 = static_cast<poly_type>(0.05336 * (1LL << IFRAC));
430 constexpr poly_type d3 = static_cast<poly_type>(0.01276 * (1LL << IFRAC));
431
432 // Extend fr to IFRAC fractional bits
433 poly_type fr_ifrac = static_cast<poly_type>(fr.mValue) << (IFRAC - FRAC_BITS);
434
435 // Horner: 1 + fr * (d0 + fr * (d1 + fr * (d2 + fr * d3)))
436 return exp2_horner(int_pow, fr_ifrac, d0, d1, d2, d3, fl::bool_constant<(IFRAC <= 16)>());
437 }
typename traits::unsigned_raw_type unsigned_raw_type
Definition base.h:32
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
constexpr FASTLED_FORCE_INLINE Derived floor() const
Definition base.h:254
typename traits::poly_intermediate_type poly_intermediate_type
Definition base.h:35
static FASTLED_FORCE_INLINE Derived exp2_horner(raw_type int_pow, PolyType fr_ifrac, PolyType d0, PolyType d1, PolyType d2, PolyType d3, fl::true_type)
Definition base.h:441
static constexpr int INT_BITS
Definition base.h:37
static constexpr auto MAX_OVERFLOW
Definition traits.h:130
static constexpr int IFRAC
Definition traits.h:120

References exp2_horner(), FASTLED_FORCE_INLINE, floor(), FRAC_BITS, fl::fixed_point_traits< IntBits, FracBits >::IFRAC, INT_BITS, fl::fixed_point_traits< IntBits, FracBits >::MAX_OVERFLOW, and fl::x.

Referenced by pow().

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