This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/3673] New: strtod exponent limit calculations broken


The strtod exponent limit calculations

          /* Get the exponent limit. */
          if (base == 16)
            exp_limit = (exp_negative ?
                         -MIN_EXP + MANT_DIG + 4 * int_no :
                         MAX_EXP - 4 * int_no + lead_zero);
          else
            exp_limit = (exp_negative ?
                         -MIN_10_EXP + MANT_DIG + int_no :
                         MAX_10_EXP - int_no + lead_zero);

have a few bugs:

* The max exponent calculation for decimals has an off-by-one error.

* The max exponent calculation for hex numbers has an off-by-three error.

* The hex calculation should use 4 * lead_zero not plain lead_zero.

(I haven't checked in detail whether the calculations for minimum exponent are
correct or not.)

This test illustrates the three problems above.  Each line of output should show
two equal numbers, but instead it says

1e+308 inf
8.98847e+307 inf
1.12356e+307 inf

because of wrong detection of overflow that wasn't there.

#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
  printf("%g %g\n", atof("1e308"), atof("100000000e300"));
  printf("%g %g\n", atof("0x1p1023"), atof("0x1000p1011"));
  printf("%g %g\n", atof("0x1p1020"), atof("0x0.00001p1040"));
  return 0;
}

-- 
           Summary: strtod exponent limit calculations broken
           Product: glibc
           Version: 2.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: jsm28 at gcc dot gnu dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=3673

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]