36 template <
typename IntT, detail::enable_if_
integer_t<IntT> = 0>
42 template <
typename OtherFP>
43 constexpr s16x16(
const OtherFP& other,
68#if defined(__riscv) && (__riscv_xlen == 32)
73 asm(
"mul %0, %2, %3\n\t"
75 :
"=&r"(lo),
"=&r"(hi)
78 (
static_cast<u32
>(lo) >> 16) | (
static_cast<u32
>(hi) << 16)));
88#if FL_FIXED_POINT_NARROW_DIVIDE
95 const u32 numerator =
mValue < 0
96 ?
static_cast<u32
>(-
static_cast<i64>(
mValue))
97 :
static_cast<u32
>(
mValue);
98 const u32 denominator =
100 :
static_cast<u32
>(b.
mValue);
109 return from_raw(
static_cast<i32
>(negative ? 0u - magnitude : magnitude));
118 static_cast<u32
>(
mValue) +
static_cast<u32
>(b.
mValue)));
123 static_cast<u32
>(
mValue) -
static_cast<u32
>(b.
mValue)));
173 return from_raw(
x.mValue < 0 ? -
x.mValue :
x.mValue);
177 return x.mValue > 0 ? 1 : (
x.mValue < 0 ? -1 : 0);
180#if defined(__riscv) && (__riscv_xlen == 32)
185 return a + (b - a) *
t;
189 return x < lo ? lo : (
x > hi ? hi :
x);
197 constexpr s16x16 zero(0.0f);
198 constexpr s16x16 one(1.0f);
199 constexpr s16x16 two(2.0f);
200 constexpr s16x16 three(3.0f);
202 return t *
t * (three - two *
t);
208 constexpr s16x16 one(1.0f);
209 constexpr s16x16 pi_over_2(1.5707963f);
210 bool neg =
x.mValue < 0;
222 constexpr s16x16 pi(3.1415926f);
223 constexpr s16x16 pi_over_2(1.5707963f);
224 if (
x.mValue == 0 &&
y.mValue == 0)
return s16x16();
225 if (
x.mValue == 0)
return y.mValue > 0 ? pi_over_2 : -pi_over_2;
226 if (
y.mValue == 0)
return x.mValue > 0 ?
s16x16() : pi;
235 if (
x.mValue < 0) a = pi - a;
236 if (
y.mValue < 0) a = -a;
241 constexpr s16x16 one(1.0f);
246 constexpr s16x16 one(1.0f);
280 if (base.mValue <= 0)
return s16x16();
281 constexpr s16x16 one(1.0f);
282 if (
exp.mValue == 0)
return one;
283 if (base == one)
return one;
286 constexpr i32 kOneRaw =
static_cast<i32
>(
SCALE);
287 if (base.mValue >= (kOneRaw - 2) && base.mValue <= kOneRaw) {
376 : (v & 0x00000002u) ? r + 1
385 u32 val =
static_cast<u32
>(
x.mValue);
390 t =
static_cast<i32
>(
393 t =
static_cast<i32
>(
398 constexpr int IFRAC = 24;
399 constexpr i64 c0 = 24189248LL;
400 constexpr i64 c1 = -11728384LL;
401 constexpr i64 c2 = 6098176LL;
402 constexpr i64 c3 = -1788416LL;
407 acc = c2 + ((acc * t24) >> IFRAC);
408 acc = c1 + ((acc * t24) >> IFRAC);
409 acc = c0 + ((acc * t24) >> IFRAC);
410 i64 frac_part = (acc * t24) >> IFRAC;
412 i32 frac16 =
static_cast<i32
>(frac_part >> (IFRAC -
FRAC_BITS));
413 return from_raw(
static_cast<i32
>(
static_cast<u32
>(int_part) <<
FRAC_BITS) + frac16);
427 int_pow =
static_cast<i32
>(
SCALE) << n;
429 int_pow =
static_cast<i32
>(
SCALE) >> (-n);
433 constexpr int IFRAC = 24;
434 constexpr i64 d0 = 11629376LL;
435 constexpr i64 d1 = 4038400LL;
436 constexpr i64 d2 = 895232LL;
437 constexpr i64 d3 = 214016LL;
442 acc = d2 + ((acc * fr24) >> IFRAC);
443 acc = d1 + ((acc * fr24) >> IFRAC);
444 acc = d0 + ((acc * fr24) >> IFRAC);
445 constexpr i64 one24 = 1LL << IFRAC;
446 i64 frac_pow24 = one24 + ((acc * fr24) >> IFRAC);
448 i32 frac_pow16 =
static_cast<i32
>(frac_pow24 >> (IFRAC -
FRAC_BITS));
458 return static_cast<u32
>(
466 constexpr s16x16 c0(0.9998779297f);
467 constexpr s16x16 c1(-0.3269348145f);
468 constexpr s16x16 c2(0.1594085693f);
469 constexpr s16x16 c3(-0.0472106934f);
471 return t * (c0 + t2 * (c1 + t2 * (c2 + t2 * c3)));
FASTLED_FORCE_INLINE s16x16 atan() const FL_NO_EXCEPT
FASTLED_FORCE_INLINE s16x16 asin() const FL_NO_EXCEPT
constexpr float to_float() const FL_NO_EXCEPT
static constexpr i32 SCALE
static constexpr int _highest_bit_step(u32 v, int r) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 asin(s16x16 x) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 cbrt(s16x16 x) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 fract() const FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 acos(s16x16 x) FL_NO_EXCEPT
constexpr s16x16(i32 raw, RawTag) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator+(s16x16 b) const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 lerp(s16x16 a, s16x16 b, s16x16 t) FL_NO_EXCEPT
constexpr bool operator<(s16x16 b) const FL_NO_EXCEPT
static constexpr int INT_BITS
static FASTLED_FORCE_INLINE s16x16 atan_unit(s16x16 t) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 rsqrt(s16x16 x) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 sqrt(s16x16 x) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 ceil() const FL_NO_EXCEPT
constexpr bool operator==(s16x16 b) const FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 floor() const FL_NO_EXCEPT
static constexpr i32 RAD_TO_24
constexpr FASTLED_FORCE_INLINE s16x16 operator/(s16x16 b) const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE u32 angle_to_a24(s16x16 angle) FL_NO_EXCEPT
static constexpr int FRAC_BITS
constexpr bool operator>=(s16x16 b) const FL_NO_EXCEPT
constexpr i32 raw() const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE int sign(s16x16 x) FL_NO_EXCEPT
constexpr bool operator>(s16x16 b) const FL_NO_EXCEPT
FASTLED_FORCE_INLINE s16x16 sin() const FL_NO_EXCEPT
friend constexpr s16x16 operator*(i32 scalar, s16x16 fp) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 step(s16x16 edge, s16x16 x) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 fract(s16x16 x) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16(IntT n) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 cos(s16x16 angle) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 clamp(s16x16 x, s16x16 lo, s16x16 hi) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 exp2_fp(s16x16 x) FL_NO_EXCEPT
FASTLED_FORCE_INLINE s16x16 cos() const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 mod(s16x16 a, s16x16 b) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 atan(s16x16 x) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 rsqrt() const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v) FL_NO_EXCEPT
FASTLED_FORCE_INLINE s16x16 acos() const FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator-() const FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator>>(int shift) const FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 abs() const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 from_raw(i32 raw) FL_NO_EXCEPT
constexpr bool operator<=(s16x16 b) const FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 pow(s16x16 base, s16x16 exp) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 ceil(s16x16 x) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 log2_fp(s16x16 x) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 sin(s16x16 angle) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator*(s16x16 b) const FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 sqrt() const FL_NO_EXCEPT
constexpr s16x16() FL_NO_EXCEPT=default
constexpr FASTLED_FORCE_INLINE int sign() const FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 smoothstep(s16x16 edge0, s16x16 edge1, s16x16 x) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE void sincos(s16x16 angle, s16x16 &out_sin, s16x16 &out_cos) FL_NO_EXCEPT
constexpr i32 to_int() const FL_NO_EXCEPT
constexpr s16x16(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_NO_EXCEPT
constexpr bool operator!=(s16x16 b) const FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 floor(s16x16 x) FL_NO_EXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 abs(s16x16 x) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator*(i32 scalar) const FL_NO_EXCEPT
static FASTLED_FORCE_INLINE s16x16 atan2(s16x16 y, s16x16 x) FL_NO_EXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator-(s16x16 b) const FL_NO_EXCEPT
#define FL_OPTIMIZATION_LEVEL_O3_BEGIN
#define FASTLED_FORCE_INLINE
#define FL_OPTIMIZATION_LEVEL_O3_END
#define constexpr
Declares that it is possible to evaluate a value at compile time, introduced in C++11.
FASTLED_FORCE_INLINE i32 sin32(u32 angle) FL_NO_EXCEPT
FL_FIXED_POINT_DIVIDE_INLINE u32 divide64By32(u32 hi, u32 lo, u32 divisor) FL_NO_EXCEPT
(hi:lo) / divisor, for a quotient that fits 32 bits.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
FL_OPTIMIZE_FUNCTION constexpr u32 isqrt64(u64 x) FL_NO_EXCEPT
FL_OPTIMIZE_FUNCTION constexpr u32 icbrt64(u64 x) FL_NO_EXCEPT
FASTLED_FORCE_INLINE SinCos32 sincos32(u32 angle) FL_NO_EXCEPT
FASTLED_FORCE_INLINE i32 cos32(u32 angle) FL_NO_EXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NO_EXCEPT
Base definition for an LED controller.
A 64/32 -> 32 division built from 32-bit divides.