34 template <
typename IntT, detail::enable_if_
integer_t<IntT> = 0>
39 template <
typename OtherFP>
40 constexpr s4x12(
const OtherFP& other,
77 static_cast<u16
>(
mValue) +
static_cast<u16
>(b.mValue)));
82 static_cast<u16
>(
mValue) -
static_cast<u16
>(b.mValue)));
87 static_cast<u16
>(0) -
static_cast<u16
>(
mValue)));
116 return from_raw(a.mValue % b.mValue);
133 return from_raw(
x.mValue < 0 ? -
x.mValue :
x.mValue);
137 return x.mValue > 0 ? 1 : (
x.mValue < 0 ? -1 : 0);
141 return a + (b - a) *
t;
145 return x < lo ? lo : (
x > hi ? hi :
x);
153 constexpr s4x12 zero(0.0f);
154 constexpr s4x12 one(1.0f);
155 constexpr s4x12 two(2.0f);
156 constexpr s4x12 three(3.0f);
157 s4x12 t =
clamp((
x - edge0) / (edge1 - edge0), zero, one);
158 return t *
t * (three - two *
t);
164 constexpr s4x12 one(1.0f);
165 constexpr s4x12 pi_over_2(1.5707963f);
166 bool neg =
x.mValue < 0;
178 constexpr s4x12 pi(3.1415926f);
179 constexpr s4x12 pi_over_2(1.5707963f);
180 if (
x.mValue == 0 &&
y.mValue == 0)
return s4x12();
181 if (
x.mValue == 0)
return y.mValue > 0 ? pi_over_2 : -pi_over_2;
182 if (
y.mValue == 0)
return x.mValue > 0 ?
s4x12() : pi;
191 if (
x.mValue < 0) a = pi - a;
192 if (
y.mValue < 0) a = -a;
197 constexpr s4x12 one(1.0f);
202 constexpr s4x12 one(1.0f);
218 if (base.mValue <= 0)
return s4x12();
219 constexpr s4x12 one(1.0f);
220 if (
exp.mValue == 0)
return one;
221 if (base == one)
return one;
224 constexpr i16 kOneRaw =
static_cast<i16
>(
SCALE);
225 if (base.mValue >=
static_cast<i16
>(kOneRaw - 2) &&
226 base.mValue <= kOneRaw) {
313 : (v & 0x00000002u) ? r + 1
322 u32 val =
static_cast<u32
>(
x.mValue);
327 t =
static_cast<i32
>(
330 t =
static_cast<i32
>(
335 constexpr int IFRAC = 20;
336 constexpr i32 c0 = 1512456;
337 constexpr i32 c1 = -733024;
338 constexpr i32 c2 = 381136;
339 constexpr i32 c3 = -111776;
341 i32 t20 =
static_cast<i32
>(
t) << (IFRAC -
FRAC_BITS);
344 acc = c2 +
static_cast<i32
>((
static_cast<i64>(acc) * t20) >> IFRAC);
345 acc = c1 +
static_cast<i32
>((
static_cast<i64>(acc) * t20) >> IFRAC);
346 acc = c0 +
static_cast<i32
>((
static_cast<i64>(acc) * t20) >> IFRAC);
347 i32 frac_part =
static_cast<i32
>((
static_cast<i64>(acc) * t20) >> IFRAC);
349 i16 frac12 =
static_cast<i16
>(frac_part >> (IFRAC -
FRAC_BITS));
350 return from_raw(
static_cast<i16
>(
static_cast<i32
>(
static_cast<u32
>(int_part) <<
FRAC_BITS) + frac12));
364 int_pow =
static_cast<i32
>(
SCALE) << n;
366 int_pow =
static_cast<i32
>(
SCALE) >> (-n);
370 constexpr int IFRAC = 20;
371 constexpr i32 d0 = 726836;
372 constexpr i32 d1 = 252400;
373 constexpr i32 d2 = 55952;
374 constexpr i32 d3 = 13376;
379 acc = d2 +
static_cast<i32
>((
static_cast<i64>(acc) * fr20) >> IFRAC);
380 acc = d1 +
static_cast<i32
>((
static_cast<i64>(acc) * fr20) >> IFRAC);
381 acc = d0 +
static_cast<i32
>((
static_cast<i64>(acc) * fr20) >> IFRAC);
382 constexpr i32 one20 =
static_cast<i32
>(1) << IFRAC;
383 i32 frac_pow20 = one20 +
static_cast<i32
>((
static_cast<i64>(acc) * fr20) >> IFRAC);
385 i32 frac_pow12 = frac_pow20 >> (IFRAC -
FRAC_BITS);
395 return static_cast<u32
>(
403 constexpr s4x12 c0(0.9998779297f);
404 constexpr s4x12 c1(-0.3269348145f);
405 constexpr s4x12 c2(0.1594085693f);
406 constexpr s4x12 c3(-0.0472106934f);
408 return t * (c0 + t2 * (c1 + t2 * (c2 + t2 * c3)));
constexpr bool operator<=(s4x12 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 atan_unit(s4x12 t) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 acos(s4x12 x) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 pow(s4x12 base, s4x12 exp) FL_NOEXCEPT
friend constexpr s4x12 operator*(i16 scalar, s4x12 fp) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 log2_fp(s4x12 x) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 clamp(s4x12 x, s4x12 lo, s4x12 hi) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE int sign() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator*(i16 scalar) const FL_NOEXCEPT
constexpr s4x12() FL_NOEXCEPT=default
constexpr float to_float() const FL_NOEXCEPT
constexpr bool operator<(s4x12 b) const FL_NOEXCEPT
constexpr i16 to_int() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 floor() const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 exp2_fp(s4x12 x) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 sin(s4x12 angle) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 lerp(s4x12 a, s4x12 b, s4x12 t) FL_NOEXCEPT
FASTLED_FORCE_INLINE s4x12 sin() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator-(s4x12 b) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 mod(s4x12 a, s4x12 b) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator+(s4x12 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 atan(s4x12 x) FL_NOEXCEPT
constexpr bool operator==(s4x12 b) const FL_NOEXCEPT
FASTLED_FORCE_INLINE s4x12 cos() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator>>(int shift) const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 rsqrt() const FL_NOEXCEPT
FASTLED_FORCE_INLINE s4x12 asin() const FL_NOEXCEPT
FASTLED_FORCE_INLINE s4x12 acos() const FL_NOEXCEPT
constexpr s4x12(IntT n) FL_NOEXCEPT
static constexpr int FRAC_BITS
constexpr FASTLED_FORCE_INLINE s4x12 ceil() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator-() const FL_NOEXCEPT
constexpr s4x12(i16 raw, RawTag) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator/(s4x12 b) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 rsqrt(s4x12 x) FL_NOEXCEPT
constexpr bool operator>(s4x12 b) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE int sign(s4x12 x) FL_NOEXCEPT
static constexpr i32 SCALE
static constexpr FASTLED_FORCE_INLINE s4x12 floor(s4x12 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 abs() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 from_raw(i16 raw) FL_NOEXCEPT
static constexpr int INT_BITS
static FASTLED_FORCE_INLINE s4x12 smoothstep(s4x12 edge0, s4x12 edge1, s4x12 x) FL_NOEXCEPT
FASTLED_FORCE_INLINE s4x12 atan() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE u32 angle_to_a24(s4x12 angle) FL_NOEXCEPT
constexpr s4x12(const OtherFP &other, typename fl::enable_if<(OtherFP::INT_BITS<=INT_BITS) &&(OtherFP::FRAC_BITS<=FRAC_BITS) &&(OtherFP::INT_BITS !=INT_BITS||OtherFP::FRAC_BITS !=FRAC_BITS), int >::type=0) FL_NOEXCEPT
constexpr i16 raw() const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 asin(s4x12 x) FL_NOEXCEPT
static constexpr int _highest_bit_step(u32 v, int r) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 abs(s4x12 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 sqrt() const FL_NOEXCEPT
static FASTLED_FORCE_INLINE void sincos(s4x12 angle, s4x12 &out_sin, s4x12 &out_cos) FL_NOEXCEPT
constexpr bool operator>=(s4x12 b) const FL_NOEXCEPT
static constexpr i32 RAD_TO_24
static constexpr FASTLED_FORCE_INLINE s4x12 step(s4x12 edge, s4x12 x) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 fract(s4x12 x) FL_NOEXCEPT
constexpr bool operator!=(s4x12 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 cos(s4x12 angle) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 fract() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 sqrt(s4x12 x) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s4x12 ceil(s4x12 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s4x12 operator*(s4x12 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s4x12 atan2(s4x12 y, s4x12 x) FL_NOEXCEPT
#define constexpr
Declares that it is possible to evaluate a value at compile time, introduced in C++11.
FASTLED_FORCE_INLINE i32 cos32(u32 angle) FL_NOEXCEPT
FASTLED_FORCE_INLINE i32 sin32(u32 angle) FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
FL_OPTIMIZE_FUNCTION constexpr u16 isqrt32(u32 x) FL_NOEXCEPT
Base definition for an LED controller.
#define FL_OPTIMIZATION_LEVEL_O3_BEGIN
#define FASTLED_FORCE_INLINE
#define FL_OPTIMIZATION_LEVEL_O3_END