FastLED 3.10.8
Loading...
Searching...
No Matches

◆ operator/()

FASTLED_FORCE_INLINE s16x16 fl::s16x16::operator/ ( s16x16 b) const
inlineconstexpr

Definition at line 87 of file s16x16.h.

87 {
88#if FL_FIXED_POINT_NARROW_DIVIDE
89 // Same value as the expression below, without the 64-bit divide that
90 // costs a libgcc call on a core whose divider is 32 bits wide.
91 // FastLED#4307 measured that call at 47x the cost of `s8x8`'s single
92 // `SDIV`, and 36x scalar float. Magnitudes go through the unsigned
93 // routine and the sign is reapplied, which also gives the
94 // truncate-toward-zero that C++ integer division specifies.
95 const u32 numerator = mValue < 0
96 ? static_cast<u32>(-static_cast<i64>(mValue))
97 : static_cast<u32>(mValue);
98 const u32 denominator =
99 b.mValue < 0 ? static_cast<u32>(-static_cast<i64>(b.mValue))
100 : static_cast<u32>(b.mValue);
101 const u32 magnitude = divide64By32(numerator >> (32 - FRAC_BITS),
102 numerator << FRAC_BITS, denominator);
103 const bool negative = (mValue < 0) != (b.mValue < 0);
104 // Negated in unsigned space. The quotient of INT32_MIN by one is
105 // INT32_MIN, which is a representable s16.16 value of -32768.0, and
106 // negating it as a signed int is undefined -- it happened to give the
107 // right answer, which is exactly why a value comparison could not
108 // find it and UBSan could.
109 return from_raw(static_cast<i32>(negative ? 0u - magnitude : magnitude));
110#else
111 return from_raw(static_cast<i32>(
112 (static_cast<i64>(mValue) * (static_cast<i64>(SCALE))) / b.mValue));
113#endif
114 }
static constexpr i32 SCALE
Definition s16x16.h:25
static constexpr int FRAC_BITS
Definition s16x16.h:24
i32 mValue
Definition s16x16.h:364
static constexpr FASTLED_FORCE_INLINE s16x16 from_raw(i32 raw) FL_NO_EXCEPT
Definition s16x16.h:56
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.
fl::i64 i64
Definition stdint.h:221

References s16x16(), fl::divide64By32(), FASTLED_FORCE_INLINE, fl::FL_NO_EXCEPT, FRAC_BITS, from_raw(), mValue, and SCALE.

+ Here is the call graph for this function: