Skip to content

Commit c982ada

Browse files
committed
2 parents e532c98 + 0de7a21 commit c982ada

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎include/fast_float/decimal_to_binary.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ namespace detail {
6363
* -ceil(p) + q
6464
* where
6565
* p = log(5**-q)/log(2) = -q * log(5)/log(2)
66+
*
67+
* The shift must floor towards negative infinity, as an arithmetic right
68+
* shift does, but right-shifting a negative value is implementation-defined
69+
* before C++20. Biasing the product by 2048 * 65536 keeps the shifted value
70+
* non-negative without changing the result: the bias is a multiple of 2^16
71+
* and is removed again after the shift.
6672
*/
6773
constexpr fastfloat_inline am_pow_t power(am_pow_t const q) noexcept {
68-
return (((152170 + 65536) * q) >> 16) + 63;
74+
return (((152170 + 65536) * q + (2048 * 65536)) >> 16) - 2048 + 63;
6975
}
7076
} // namespace detail
7177

0 commit comments

Comments
 (0)