1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-12-24 17:51:17 +03:00

Fix strtod subnormal rounding (bug 30220)

As reported in bug 30220, the implementation of strtod-family
functions has a bug in the following case: the input string would,
with infinite exponent range, take one more bit to represent than is
available in the normal precision of the return type; the value
represented is in the subnormal range; and there are no nonzero bits
in the value, below those that can be represented in subnormal
precision, other than the least significant bit and possibly the
0.5ulp bit.  In this case, round_and_return ends up discarding the
least significant bit.

Fix by saving that bit to merge into more_bits (it can't be merged in
at the time it's computed, because more_bits mustn't include this bit
in the case of after-rounding tininess detection checking if the
result is still subnormal when rounded to normal precision, so merging
this bit into more_bits needs to take place after that check).

Tested for x86_64.
This commit is contained in:
Joseph Myers
2024-08-27 12:41:02 +00:00
parent d73ed2601b
commit 457622c2fa
3 changed files with 386 additions and 0 deletions

View File

@@ -222,6 +222,7 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative,
mp_size_t shift = MIN_EXP - 1 - exponent;
bool is_tiny = true;
bool old_half_bit = (round_limb & (((mp_limb_t) 1) << round_bit)) != 0;
more_bits |= (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0;
if (shift == MANT_DIG)
@@ -292,6 +293,7 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative,
round_bit = shift - 1;
(void) __mpn_rshift (retval, retval, RETURN_LIMB_SIZE, shift);
}
more_bits |= old_half_bit;
/* This is a hook for the m68k long double format, where the
exponent bias is the same for normalized and denormalized
numbers. */