Compare commits

...

4 Commits

Author SHA1 Message Date
HedgehogInTheCPP
c982adabbd Merge branch 'main' of https://github.com/fastfloat/fast_float 2026-10-27 23:41:35 +03:00
Daniel Lemire
0de7a21da5 Run clang-format 2026-10-17 08:55:50 -04:00
Daniel Lemire
638a8acd6d
Merge pull request #426 from sahvx655-wq/power-negative-shift
Avoid right-shifting a negative value in detail::power()
2026-10-17 08:54:58 -04:00
Sahana Bogar
90513adca1 Avoid right-shifting a negative value in detail::power() 2026-10-15 11:53:39 +05:30

View File

@ -63,9 +63,15 @@ namespace detail {
* -ceil(p) + q
* where
* p = log(5**-q)/log(2) = -q * log(5)/log(2)
*
* The shift must floor towards negative infinity, as an arithmetic right
* shift does, but right-shifting a negative value is implementation-defined
* before C++20. Biasing the product by 2048 * 65536 keeps the shifted value
* non-negative without changing the result: the bias is a multiple of 2^16
* and is removed again after the shift.
*/
constexpr fastfloat_inline am_pow_t power(am_pow_t const q) noexcept {
return (((152170 + 65536) * q) >> 16) + 63;
return (((152170 + 65536) * q + (2048 * 65536)) >> 16) - 2048 + 63;
}
} // namespace detail