| 4136 | // round an extended-precision float to the nearest machine float. |
| 4137 | template <typename T, typename callback> |
| 4138 | fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void round(adjusted_mantissa &am, |
| 4139 | callback cb) noexcept { |
| 4140 | int32_t mantissa_shift = 64 - binary_format<T>::mantissa_explicit_bits() - 1; |
| 4141 | if (-am.power2 >= mantissa_shift) { |
| 4142 | // have a denormal float |
| 4143 | int32_t shift = -am.power2 + 1; |
| 4144 | cb(am, (shift < 64 ? shift : 64)); |
| 4145 | // check for round-up: if rounding-nearest carried us to the hidden bit. |
| 4146 | am.power2 = (am.mantissa < |
| 4147 | (uint64_t(1) << binary_format<T>::mantissa_explicit_bits())) |
| 4148 | ? 0 |
| 4149 | : 1; |
| 4150 | return; |
| 4151 | } |
| 4152 | |
| 4153 | // have a normal float, use the default shift. |
| 4154 | cb(am, mantissa_shift); |
| 4155 | |
| 4156 | // check for carry |
| 4157 | if (am.mantissa >= |
| 4158 | (uint64_t(2) << binary_format<T>::mantissa_explicit_bits())) { |
| 4159 | am.mantissa = (uint64_t(1) << binary_format<T>::mantissa_explicit_bits()); |
| 4160 | am.power2++; |
| 4161 | } |
| 4162 | |
| 4163 | // check for infinite: we could have carried to an infinite power |
| 4164 | am.mantissa &= ~(uint64_t(1) << binary_format<T>::mantissa_explicit_bits()); |
| 4165 | if (am.power2 >= binary_format<T>::infinite_power()) { |
| 4166 | am.power2 = binary_format<T>::infinite_power(); |
| 4167 | am.mantissa = 0; |
| 4168 | } |
| 4169 | } |
| 4170 | |
| 4171 | template <typename callback> |
| 4172 | fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void |
no outgoing calls
no test coverage detected