mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-10-28 18:07:16 +08:00
Avoid right-shifting a negative value in subnormal_ties_possible()
This commit is contained in:
parent
20a9b35333
commit
82623d83c5
@ -1117,11 +1117,12 @@ inline constexpr bool binary_format<T>::fast_path_can_overflow() {
|
||||
|
||||
// A subnormal needs w * 10^q < 2^(minimum_exponent() + 1), so q is at most
|
||||
// (minimum_exponent() + 1) * log10(2), with 1233/4096 < log10(2). Only
|
||||
// std::float16_t has such q in its round-to-even range.
|
||||
// std::float16_t has such q in its round-to-even range. We compare
|
||||
// 4096 * q with (minimum_exponent() + 1) * 1233 to avoid right-shifting a
|
||||
// negative value (implementation-defined before C++20).
|
||||
template <typename T>
|
||||
inline constexpr bool binary_format<T>::subnormal_ties_possible() {
|
||||
return min_exponent_round_to_even() <=
|
||||
(((minimum_exponent() + 1) * 1233) >> 12);
|
||||
return min_exponent_round_to_even() * 4096 <= (minimum_exponent() + 1) * 1233;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user