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

◆ ieee754_bits_from_scaled_u64()

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

Definition at line 159 of file json.h.

162 {
163 if (magnitude == 0) {
164 return sign;
165 }
166
167 const int top_bit = json_floor_log2_u64(magnitude);
168 int exponent = top_bit + binary_exp;
169 if (exponent > 127) {
170 return sign | 0x7F800000u;
171 }
172
173 if (exponent >= -126) {
174 const int shift = top_bit - 23;
175 u32 significand = 0;
176 if (shift > 0) {
177 significand = round_shift_right_u64(magnitude, shift);
178 } else {
179 significand = static_cast<u32>(magnitude << -shift);
180 }
181 if (significand >= 0x01000000u) {
182 significand >>= 1;
183 ++exponent;
184 if (exponent > 127) {
185 return sign | 0x7F800000u;
186 }
187 }
188 return sign | (static_cast<u32>(exponent + 127) << 23) |
189 (significand & 0x007FFFFFu);
190 }
191
192 const int subnormal_shift = -(binary_exp + 149);
193 u32 mantissa = 0;
194 if (subnormal_shift > 0) {
195 mantissa = round_shift_right_u64(magnitude, subnormal_shift);
196 } else {
197 const int left_shift = -subnormal_shift;
198 if (left_shift >= 64 || magnitude > (u64(-1) >> left_shift)) {
199 return sign | 0x7F800000u;
200 }
201 const u64 shifted = magnitude << left_shift;
202 mantissa = shifted > 0x007FFFFFu ? 0x00800000u : static_cast<u32>(shifted);
203 }
204 if (mantissa >= 0x00800000u) {
205 return sign | 0x00800000u;
206 }
u32 round_shift_right_u64(u64 value, int shift) FL_NO_EXCEPT
Definition json.h:144
int json_floor_log2_u64(u64 value) FL_NO_EXCEPT
Definition types_impl.h:18
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NO_EXCEPT
fl::u64 u64
Definition stdint.h:220