FastLED 3.10.6
Loading...
Searching...
No Matches

◆ soft_float_bits_from_scaled_u64()

u32 fl::detail::soft_float_bits_from_scaled_u64 ( u32 sign,
u64 magnitude,
int binary_exp )
inline

Definition at line 82 of file soft_float.h.

83 {
84 if (magnitude == 0) {
85 return sign;
86 }
87
88 const int top_bit = soft_floor_log2_u64(magnitude);
89 int exponent = top_bit + binary_exp;
90 if (exponent > 127) {
91 return sign | 0x7F800000u;
92 }
93
94 if (exponent >= -126) {
95 const int shift = top_bit - 23;
96 u32 significand = shift > 0
97 ? soft_round_shift_right_u64(magnitude, shift)
98 : static_cast<u32>(magnitude << -shift);
99 if (significand >= 0x01000000u) {
100 significand >>= 1;
101 ++exponent;
102 if (exponent > 127) {
103 return sign | 0x7F800000u;
104 }
105 }
106 return sign | (static_cast<u32>(exponent + 127) << 23) |
107 (significand & 0x007FFFFFu);
108 }
109
110 const int subnormal_shift = -(binary_exp + 149);
111 u32 mantissa = 0;
112 if (subnormal_shift > 0) {
113 mantissa = soft_round_shift_right_u64(magnitude, subnormal_shift);
114 } else {
115 const int left_shift = -subnormal_shift;
116 if (left_shift >= 64 || magnitude > (u64(-1) >> left_shift)) {
117 return sign | 0x7F800000u;
118 }
119 const u64 shifted = magnitude << left_shift;
120 mantissa = shifted > 0x007FFFFFu ? 0x00800000u : static_cast<u32>(shifted);
121 }
122 if (mantissa >= 0x00800000u) {
123 return sign | 0x00800000u;
124 }
125 return sign | mantissa;
126}
int soft_floor_log2_u64(u64 value) FL_NO_EXCEPT
Definition soft_float.h:73
u32 soft_round_shift_right_u64(u64 value, int shift) FL_NO_EXCEPT
Definition soft_float.h:58
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NO_EXCEPT
fl::u64 u64
Definition stdint.h:220

References fl::FL_NO_EXCEPT, fl::sign(), soft_floor_log2_u64(), and soft_round_shift_right_u64().

Referenced by json_ieee754_float_bits_from_scaled_u64(), and fl::soft_float_bits_from_double_bits().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: