]> git.ipfire.org Git - thirdparty/glibc.git/commit
Fix strtod subnormal rounding (bug 30220)
authorJoseph Myers <josmyers@redhat.com>
Tue, 27 Aug 2024 12:41:02 +0000 (12:41 +0000)
committerArjun Shankar <arjun@redhat.com>
Fri, 27 Sep 2024 15:25:43 +0000 (17:25 +0200)
commita7be595c67d12f1a442e3f6894d67e20c7724bed
treeb9244e6a031ce4ae02f8bf91855013129d1f9941
parent9cfeccf65ab8aedb2353d89a1ef8b4e775d6f925
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.

(cherry picked from commit 457622c2fa8f9f7435822d5287a437bc8be8090d)
stdlib/strtod_l.c
stdlib/tst-strtod-round-data
stdlib/tst-strtod-round-data.h