From: Bruno Haible Date: Sat, 24 Feb 2007 16:31:38 +0000 (+0000) Subject: Fix a bug with 1.0. X-Git-Tag: cvs-readonly~989 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=92f4139cf45cd23105f61e8d7c9e8d06ab719d7e;p=gnulib.git Fix a bug with 1.0. --- diff --git a/ChangeLog b/ChangeLog index ae7b937dd..1c3626cf6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-02-24 Bruno Haible + + * lib/frexpl.c (frexpl): Correct return values for x = 1.0L. Don't + assume that an exponent fits in 20 bits. + 2007-02-24 Jim Meyering * m4/regex.m4: Update the description of the configure-time option, diff --git a/lib/frexpl.c b/lib/frexpl.c index c563fc0c9..f78c4000d 100644 --- a/lib/frexpl.c +++ b/lib/frexpl.c @@ -30,11 +30,14 @@ long double frexpl(long double x, int *exp) { - long double exponents[20], *next; + /* Since the exponent is an 'int', it fits in 64 bits. Therefore the + loops are executed no more than 64 times. */ + long double exponents[64]; + long double *next; int exponent, bit; /* Check for zero, nan and infinity. */ - if (x != x || x + x == x ) + if (x != x || x + x == x) { *exp = 0; return x; @@ -44,7 +47,7 @@ frexpl(long double x, int *exp) return -frexpl(-x, exp); exponent = 0; - if (x > 1.0) + if (x >= 1.0) { for (next = exponents, exponents[0] = 2.0L, bit = 1; *next <= x + x; @@ -90,6 +93,7 @@ main (void) x = frexpl(-1.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y); x = frexpl(0.5L, &y); printf ("%.6Lg %d\n", x, y); x = frexpl(0.75L, &y); printf ("%.6Lg %d\n", x, y); + x = frexpl(1.0L, &y); printf ("%.6Lg %d\n", x, y); x = frexpl(3.6L, &y); printf ("%.6Lg %d\n", x, y); x = frexpl(17.8L, &y); printf ("%.6Lg %d\n", x, y); x = frexpl(8.0L, &y); printf ("%.6Lg %d\n", x, y);