From: Eric Blake Date: Sun, 30 Mar 2008 21:57:54 +0000 (-0600) Subject: More strtod touchups. X-Git-Tag: v0.1~7631^2 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=35029b9098fbe10eeb3ba5833ee5f01b77c5d883;p=gnulib.git More strtod touchups. * tests/test-strtod.c (main): Ignore tests for signbit on NaN, and sign of negative underflow, for now. Use .5, not .1. * doc/posix-functions/strtod.texi (strtod): Mention these limitations. Reported by Jim Meyering. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 5df926741..117ff3d04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,15 @@ 2008-03-30 Eric Blake + More strtod touchups. + * tests/test-strtod.c (main): Ignore tests for signbit on NaN, and + sign of negative underflow, for now. Use .5, not .1. + * doc/posix-functions/strtod.texi (strtod): Mention these + limitations. + Reported by Jim Meyering. + +2008-03-30 Eric Blake + strtod touchups. * lib/strtod.c (strtod): Avoid compiler warnings. Reported by Jim Meyering. diff --git a/doc/posix-functions/strtod.texi b/doc/posix-functions/strtod.texi index fecade38d..6e137ddd9 100644 --- a/doc/posix-functions/strtod.texi +++ b/doc/posix-functions/strtod.texi @@ -52,7 +52,12 @@ Portability problems not fixed by Gnulib: @item This function returns a positive value for negative underflow on some platforms: -glibc 2.4, Mingw, Cygwin. +glibc 2.7, Mingw, Cygwin. + +@item +This function cannot distinguish between ``nan'' and ``-nan'' on some +platforms: +glibc 2.7. @item This function fails to correctly parse very long strings on some diff --git a/tests/test-strtod.c b/tests/test-strtod.c index 59fe7e74c..996e3da56 100644 --- a/tests/test-strtod.c +++ b/tests/test-strtod.c @@ -143,10 +143,10 @@ main () } { errno = 0; - const char input[] = ".1"; + const char input[] = ".5"; char *ptr; double result = strtod (input, &ptr); - ASSERT (result == 0.1); + ASSERT (result == 0.5); ASSERT (ptr == input + 2); ASSERT (errno == 0); } @@ -215,10 +215,10 @@ main () } { errno = 0; - const char input[] = "1e-1"; + const char input[] = "5e-1"; char *ptr; double result = strtod (input, &ptr); - ASSERT (result == 0.1); + ASSERT (result == 0.5); ASSERT (ptr == input + 4); ASSERT (errno == 0); } @@ -443,7 +443,7 @@ main () /* Overflow/underflow. */ { errno = 0; - const char input[] = "1E100000"; + const char input[] = "1E1000000"; char *ptr; double result = strtod (input, &ptr); ASSERT (result == HUGE_VAL); @@ -452,7 +452,7 @@ main () } { errno = 0; - const char input[] = "-1E100000"; + const char input[] = "-1E1000000"; char *ptr; double result = strtod (input, &ptr); ASSERT (result == -HUGE_VAL); @@ -475,7 +475,13 @@ main () char *ptr; double result = strtod (input, &ptr); ASSERT (-FLT_MIN <= result && result <= 0.0); +#if 0 + /* FIXME - this is glibc bug 5995; POSIX allows returning positive + 0 on negative underflow, even though quality of implementation + demands preserving the sign. Disable this test until fixed + glibc is more prevalent. */ ASSERT (signbit (result) == signbit (-0.0)); +#endif ASSERT (ptr == input + 10); ASSERT (errno == ERANGE); } @@ -539,7 +545,11 @@ main () #ifdef NAN ASSERT (isnan (result1)); ASSERT (isnan (result2)); +# if 0 + /* Sign bits of NaN is a portability sticking point, not worth + worrying about. */ ASSERT (signbit (result1) != signbit (result2)); +# endif ASSERT (ptr1 == input + 4); ASSERT (ptr2 == input + 4); ASSERT (errno == 0); @@ -587,7 +597,11 @@ main () #ifdef NAN ASSERT (isnan (result1)); ASSERT (isnan (result2)); +# if 0 + /* Sign bits of NaN is a portability sticking point, not worth + worrying about. */ ASSERT (signbit (result1) != signbit (result2)); +# endif ASSERT (ptr1 == input + 6); ASSERT (ptr2 == input + 6); ASSERT (errno == 0); @@ -630,7 +644,11 @@ main () #ifdef NAN ASSERT (isnan (result1)); ASSERT (isnan (result2)); +# if 0 + /* Sign bits of NaN is a portability sticking point, not worth + worrying about. */ ASSERT (signbit (result1) != signbit (result2)); +# endif ASSERT (ptr1 == input + 7); ASSERT (ptr2 == input + 7); ASSERT (errno == 0);