| 2542 | // round an extended-precision float to the nearest machine float. |
| 2543 | template <typename T, typename callback> |
| 2544 | fastfloat_really_inline void round(adjusted_mantissa& am, callback cb) noexcept { |
| 2545 | int32_t mantissa_shift = 64 - binary_format<T>::mantissa_explicit_bits() - 1; |
| 2546 | if (-am.power2 >= mantissa_shift) { |
| 2547 | // have a denormal float |
| 2548 | int32_t shift = -am.power2 + 1; |
| 2549 | cb(am, std::min(shift, 64)); |
| 2550 | // check for round-up: if rounding-nearest carried us to the hidden bit. |
| 2551 | am.power2 = (am.mantissa < (uint64_t(1) << binary_format<T>::mantissa_explicit_bits())) ? 0 : 1; |
| 2552 | return; |
| 2553 | } |
| 2554 | |
| 2555 | // have a normal float, use the default shift. |
| 2556 | cb(am, mantissa_shift); |
| 2557 | |
| 2558 | // check for carry |
| 2559 | if (am.mantissa >= (uint64_t(2) << binary_format<T>::mantissa_explicit_bits())) { |
| 2560 | am.mantissa = (uint64_t(1) << binary_format<T>::mantissa_explicit_bits()); |
| 2561 | am.power2++; |
| 2562 | } |
| 2563 | |
| 2564 | // check for infinite: we could have carried to an infinite power |
| 2565 | am.mantissa &= ~(uint64_t(1) << binary_format<T>::mantissa_explicit_bits()); |
| 2566 | if (am.power2 >= binary_format<T>::infinite_power()) { |
| 2567 | am.power2 = binary_format<T>::infinite_power(); |
| 2568 | am.mantissa = 0; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | template <typename callback> |
| 2573 | fastfloat_really_inline |
no test coverage detected