| 4674 | |
| 4675 | template <typename T> |
| 4676 | fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool |
| 4677 | clinger_fast_path_impl(uint64_t mantissa, int64_t exponent, bool is_negative, |
| 4678 | T &value) noexcept { |
| 4679 | // The implementation of the Clinger's fast path is convoluted because |
| 4680 | // we want round-to-nearest in all cases, irrespective of the rounding mode |
| 4681 | // selected on the thread. |
| 4682 | // We proceed optimistically, assuming that detail::rounds_to_nearest() |
| 4683 | // returns true. |
| 4684 | if (binary_format<T>::min_exponent_fast_path() <= exponent && |
| 4685 | exponent <= binary_format<T>::max_exponent_fast_path()) { |
| 4686 | // Unfortunately, the conventional Clinger's fast path is only possible |
| 4687 | // when the system rounds to the nearest float. |
| 4688 | // |
| 4689 | // We expect the next branch to almost always be selected. |
| 4690 | // We could check it first (before the previous branch), but |
| 4691 | // there might be performance advantages at having the check |
| 4692 | // be last. |
| 4693 | if (!cpp20_and_in_constexpr() && detail::rounds_to_nearest()) { |
| 4694 | // We have that fegetround() == FE_TONEAREST. |
| 4695 | // Next is Clinger's fast path. |
| 4696 | if (mantissa <= binary_format<T>::max_mantissa_fast_path()) { |
| 4697 | value = T(mantissa); |
| 4698 | if (exponent < 0) { |
| 4699 | value = value / binary_format<T>::exact_power_of_ten(-exponent); |
| 4700 | } else { |
| 4701 | value = value * binary_format<T>::exact_power_of_ten(exponent); |
| 4702 | } |
| 4703 | if (is_negative) { |
| 4704 | value = -value; |
| 4705 | } |
| 4706 | return true; |
| 4707 | } |
| 4708 | } else { |
| 4709 | // We do not have that fegetround() == FE_TONEAREST. |
| 4710 | // Next is a modified Clinger's fast path, inspired by Jakub Jelínek's |
| 4711 | // proposal |
| 4712 | if (exponent >= 0 && |
| 4713 | mantissa <= binary_format<T>::max_mantissa_fast_path(exponent)) { |
| 4714 | #if defined(__clang__) || defined(FASTFLOAT_32BIT) |
| 4715 | // Clang may map 0 to -0.0 when fegetround() == FE_DOWNWARD |
| 4716 | if (mantissa == 0) { |
| 4717 | value = is_negative ? T(-0.) : T(0.); |
| 4718 | return true; |
| 4719 | } |
| 4720 | #endif |
| 4721 | value = T(mantissa) * binary_format<T>::exact_power_of_ten(exponent); |
| 4722 | if (is_negative) { |
| 4723 | value = -value; |
| 4724 | } |
| 4725 | return true; |
| 4726 | } |
| 4727 | } |
| 4728 | } |
| 4729 | return false; |
| 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * This function overload takes parsed_number_string_t structure that is created |
no test coverage detected