34 template <
typename IntT, detail::enable_if_
integer_t<IntT> = 0>
40 template <
typename OtherFP>
41 constexpr s16x16(
const OtherFP& other,
66#if defined(__riscv) && (__riscv_xlen == 32)
71 asm(
"mul %0, %2, %3\n\t"
73 :
"=&r"(lo),
"=&r"(hi)
76 (
static_cast<u32
>(lo) >> 16) | (
static_cast<u32
>(hi) << 16)));
147 return from_raw(
x.mValue < 0 ? -
x.mValue :
x.mValue);
151 return x.mValue > 0 ? 1 : (
x.mValue < 0 ? -1 : 0);
154#if defined(__riscv) && (__riscv_xlen == 32)
159 return a + (b - a) *
t;
163 return x < lo ? lo : (
x > hi ? hi :
x);
171 constexpr s16x16 zero(0.0f);
172 constexpr s16x16 one(1.0f);
173 constexpr s16x16 two(2.0f);
174 constexpr s16x16 three(3.0f);
176 return t *
t * (three - two *
t);
182 constexpr s16x16 one(1.0f);
183 constexpr s16x16 pi_over_2(1.5707963f);
184 bool neg =
x.mValue < 0;
196 constexpr s16x16 pi(3.1415926f);
197 constexpr s16x16 pi_over_2(1.5707963f);
198 if (
x.mValue == 0 &&
y.mValue == 0)
return s16x16();
199 if (
x.mValue == 0)
return y.mValue > 0 ? pi_over_2 : -pi_over_2;
200 if (
y.mValue == 0)
return x.mValue > 0 ?
s16x16() : pi;
209 if (
x.mValue < 0) a = pi - a;
210 if (
y.mValue < 0) a = -a;
215 constexpr s16x16 one(1.0f);
220 constexpr s16x16 one(1.0f);
236 if (base.mValue <= 0)
return s16x16();
237 constexpr s16x16 one(1.0f);
238 if (
exp.mValue == 0)
return one;
239 if (base == one)
return one;
242 constexpr i32 kOneRaw =
static_cast<i32
>(
SCALE);
243 if (base.mValue >= (kOneRaw - 2) && base.mValue <= kOneRaw) {
332 : (v & 0x00000002u) ? r + 1
341 u32 val =
static_cast<u32
>(
x.mValue);
346 t =
static_cast<i32
>(
349 t =
static_cast<i32
>(
354 constexpr int IFRAC = 24;
355 constexpr i64 c0 = 24189248LL;
356 constexpr i64 c1 = -11728384LL;
357 constexpr i64 c2 = 6098176LL;
358 constexpr i64 c3 = -1788416LL;
363 acc = c2 + ((acc * t24) >> IFRAC);
364 acc = c1 + ((acc * t24) >> IFRAC);
365 acc = c0 + ((acc * t24) >> IFRAC);
366 i64 frac_part = (acc * t24) >> IFRAC;
368 i32 frac16 =
static_cast<i32
>(frac_part >> (IFRAC -
FRAC_BITS));
369 return from_raw(
static_cast<i32
>(
static_cast<u32
>(int_part) <<
FRAC_BITS) + frac16);
383 int_pow =
static_cast<i32
>(
SCALE) << n;
385 int_pow =
static_cast<i32
>(
SCALE) >> (-n);
389 constexpr int IFRAC = 24;
390 constexpr i64 d0 = 11629376LL;
391 constexpr i64 d1 = 4038400LL;
392 constexpr i64 d2 = 895232LL;
393 constexpr i64 d3 = 214016LL;
398 acc = d2 + ((acc * fr24) >> IFRAC);
399 acc = d1 + ((acc * fr24) >> IFRAC);
400 acc = d0 + ((acc * fr24) >> IFRAC);
401 constexpr i64 one24 = 1LL << IFRAC;
402 i64 frac_pow24 = one24 + ((acc * fr24) >> IFRAC);
404 i32 frac_pow16 =
static_cast<i32
>(frac_pow24 >> (IFRAC -
FRAC_BITS));
414 return static_cast<u32
>(
422 constexpr s16x16 c0(0.9998779297f);
423 constexpr s16x16 c1(-0.3269348145f);
424 constexpr s16x16 c2(0.1594085693f);
425 constexpr s16x16 c3(-0.0472106934f);
427 return t * (c0 + t2 * (c1 + t2 * (c2 + t2 * c3)));
static constexpr FASTLED_FORCE_INLINE s16x16 sqrt(s16x16 x) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 log2_fp(s16x16 x) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE int highest_bit(u32 v) FL_NOEXCEPT
constexpr float to_float() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 ceil() const FL_NOEXCEPT
static constexpr i32 SCALE
static FASTLED_FORCE_INLINE void sincos(s16x16 angle, s16x16 &out_sin, s16x16 &out_cos) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 mod(s16x16 a, s16x16 b) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE int sign() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 clamp(s16x16 x, s16x16 lo, s16x16 hi) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 ceil(s16x16 x) FL_NOEXCEPT
constexpr s16x16(IntT n) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 floor() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator/(s16x16 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 atan(s16x16 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 rsqrt() const FL_NOEXCEPT
static constexpr int INT_BITS
static FASTLED_FORCE_INLINE s16x16 sin(s16x16 angle) FL_NOEXCEPT
constexpr bool operator!=(s16x16 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 asin(s16x16 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 sqrt() const FL_NOEXCEPT
constexpr i32 to_int() const FL_NOEXCEPT
static constexpr i32 RAD_TO_24
constexpr s16x16() FL_NOEXCEPT=default
constexpr FASTLED_FORCE_INLINE s16x16 fract() const FL_NOEXCEPT
FASTLED_FORCE_INLINE s16x16 cos() const FL_NOEXCEPT
static constexpr int FRAC_BITS
static FASTLED_FORCE_INLINE s16x16 exp2_fp(s16x16 x) FL_NOEXCEPT
constexpr bool operator>(s16x16 b) const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator-() const FL_NOEXCEPT
constexpr bool operator>=(s16x16 b) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 fract(s16x16 x) FL_NOEXCEPT
FASTLED_FORCE_INLINE s16x16 asin() const FL_NOEXCEPT
FASTLED_FORCE_INLINE s16x16 atan() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 floor(s16x16 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 abs() const FL_NOEXCEPT
constexpr s16x16(i32 raw, RawTag) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 from_raw(i32 raw) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 smoothstep(s16x16 edge0, s16x16 edge1, s16x16 x) FL_NOEXCEPT
constexpr i32 raw() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 abs(s16x16 x) FL_NOEXCEPT
constexpr bool operator==(s16x16 b) const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator-(s16x16 b) const FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 cos(s16x16 angle) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator+(s16x16 b) const FL_NOEXCEPT
FASTLED_FORCE_INLINE s16x16 sin() const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE u32 angle_to_a24(s16x16 angle) FL_NOEXCEPT
constexpr bool operator<(s16x16 b) const FL_NOEXCEPT
FASTLED_FORCE_INLINE s16x16 acos() const FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator>>(int shift) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE int sign(s16x16 x) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 pow(s16x16 base, s16x16 exp) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator*(s16x16 b) const FL_NOEXCEPT
static constexpr int _highest_bit_step(u32 v, int r) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 acos(s16x16 x) FL_NOEXCEPT
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_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 atan2(s16x16 y, s16x16 x) FL_NOEXCEPT
constexpr bool operator<=(s16x16 b) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 step(s16x16 edge, s16x16 x) FL_NOEXCEPT
constexpr FASTLED_FORCE_INLINE s16x16 operator*(i32 scalar) const FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 rsqrt(s16x16 x) FL_NOEXCEPT
friend constexpr s16x16 operator*(i32 scalar, s16x16 fp) FL_NOEXCEPT
static FASTLED_FORCE_INLINE s16x16 atan_unit(s16x16 t) FL_NOEXCEPT
static constexpr FASTLED_FORCE_INLINE s16x16 lerp(s16x16 a, s16x16 b, s16x16 t) 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)
FASTLED_FORCE_INLINE SinCos32 sincos32(u32 angle) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
FL_OPTIMIZE_FUNCTION constexpr u32 isqrt64(u64 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