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

◆ fixed_raw_from_ieee754_bits()

bool fl::detail::fixed_raw_from_ieee754_bits ( u32 bits,
int frac_bits,
i64 * out )
inline

Definition at line 216 of file json.h.

218 {
219 const bool negative = (bits & 0x80000000u) != 0;
220 const u32 exp_bits = (bits >> 23) & 0xFFu;
221 const u32 mantissa_bits = bits & 0x007FFFFFu;
222 if (exp_bits == 0xFFu) {
223 return false;
224 }
225
226 u64 significand = mantissa_bits;
227 int exponent = -126;
228 if (exp_bits != 0) {
229 significand |= 0x00800000u;
230 exponent = static_cast<int>(exp_bits) - 127;
231 }
232
233 const int shift = exponent + frac_bits - 23;
234 u64 magnitude = 0;
235 if (shift >= 0) {
236 if (shift >= 63 || significand > (u64(0x7FFFFFFFFFFFFFFF) >> shift)) {
237 return false;
238 }
239 magnitude = significand << shift;
240 } else {
241 magnitude = round_shift_right_u64(significand, -shift);
242 }
243 if ((!negative && magnitude > u64(0x7FFFFFFFFFFFFFFF)) ||
244 (negative && magnitude > (u64(0x7FFFFFFFFFFFFFFF) + 1u))) {
245 return false;
246 }
247 *out = negative
248 ? (magnitude == (u64(0x7FFFFFFFFFFFFFFF) + 1u)
249 ? static_cast<i64>(0x8000000000000000ull)
250 : -static_cast<i64>(magnitude))
251 : static_cast<i64>(magnitude);
u32 round_shift_right_u64(u64 value, int shift) FL_NO_EXCEPT
Definition json.h:144
fl::u64 u64
Definition stdint.h:220
fl::i64 i64
Definition stdint.h:221

Referenced by fl::json::as_fixed_point().

+ Here is the caller graph for this function: