summaryrefslogtreecommitdiff
path: root/stdlib/strtod_l.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-10-28 00:40:23 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-10-28 00:40:23 +0000
commit4725d33eed118d69b8110285f7741cde9ddc8b4f (patch)
treebe10b6e9854beb628d9b6021dab98ad03efebf4b /stdlib/strtod_l.c
parent61668b22f5d0efac44bbedad0e738faa6f0820ff (diff)
downloadglibc-4725d33eed118d69b8110285f7741cde9ddc8b4f.tar.gz
Make strtod raise "inexact" exceptions (bug 19380).
The strtod function should raise the "inexact" exception when its result is inexact, but fails to do so except in the case of underflow or overflow. This patch fixes it to do so for all inexact results. tst-strtod-round is extended to test for this exception; the generator is fixed to properly mark inexact results as such in the case where the inexactness is from the mpfr_subnormalize step. Tested for x86_64, x86 and powerpc. [BZ #19380] * stdlib/strtod_l.c (round_and_return): Force "inexact" exception for inexact results. * stdlib/gen-tst-strtod-round.c (string_to_fp): Return indication of inexact result where mpfr_subnormalize is the only inexact step. * stdlib/tst-strtod-round-data.h: Regenerated. * stdlib/tst-strtod-round-skeleton.c [!FE_INEXACT] (FE_INEXACT): Define to 0. (GEN_ONE_TEST): Test inexact exceptions raised are as expected.
Diffstat (limited to 'stdlib/strtod_l.c')
-rw-r--r--stdlib/strtod_l.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c
index 3d66eac706..a6c226ee9f 100644
--- a/stdlib/strtod_l.c
+++ b/stdlib/strtod_l.c
@@ -294,11 +294,14 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative,
if (exponent > MAX_EXP)
goto overflow;
+ bool half_bit = (round_limb & (((mp_limb_t) 1) << round_bit)) != 0;
+ bool more_bits_nonzero
+ = (more_bits
+ || (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0);
if (round_away (negative,
(retval[0] & 1) != 0,
- (round_limb & (((mp_limb_t) 1) << round_bit)) != 0,
- (more_bits
- || (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0),
+ half_bit,
+ more_bits_nonzero,
mode))
{
mp_limb_t cy = __mpn_add_1 (retval, retval, RETURN_LIMB_SIZE, 1);
@@ -325,6 +328,11 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative,
overflow:
return overflow_value (negative);
+ if (half_bit || more_bits_nonzero)
+ {
+ FLOAT force_inexact = (FLOAT) 1 + MIN_VALUE;
+ math_force_eval (force_inexact);
+ }
return MPN2FLOAT (retval, exponent, negative);
}