This is sources Bugzilla
Bugzilla Version 2.17.5
Bugzilla Bug 6467
  strtod "0.0" returns nonzero Last modified: 2008-04-29 19:43
     Query page      Enter new bug
Bug#: 6467   Hardware:   Reporter: Pete Eberlein <eberlein@us.ibm.com>
Host: Target: Build:
Product:     Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: RESOLVED   Priority:  
Resolution: INVALID   Severity:  
Assigned To: Ulrich Drepper <drepper@redhat.com>   Target Milestone:  
Flags: Requestee:
  backport ()
  examined ()
  testsuite ()
Summary:
Keywords:

Attachment Description Type Created Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 6467 depends on: Show dependency tree
Show dependency graph
Bug 6467 blocks:

Additional Comments:


Leave as RESOLVED INVALID
Reopen bug
Mark bug as VERIFIED

View Bug Activity   |   Format For Printing


Description:   Last confirmed: 0000-00-00 00:00 Opened: 2008-04-29 17:59
Consider the following code snippet.

printf("%g", strtof("0.0", NULL))
printf("%lg", strtod("0.0", NULL))
printf("%llg", strtold("0.0", NULL))

When executed, expecting to see zeroes, the output is: 

2.216671e-231
2.216671e-231
2.216671e-231

This seems to be due to strtod_l.c setting
 int_no is 0
 lead_zero = -1 
and later 
 dig_no -= lead_zero
This increases the number of digits considered for fractional digits since
 dig_no - int_no
is passed to str_to_mpn.  This causes the null string terminator to be
considered as a digit in the fractional digits.

------- Additional Comment #1 From Jakub Jelinek 2008-04-29 18:48 -------
It would be helpful if you could say on which target that is, because I
definitely can't reproduce it, neither on x86_64, nor on ppc32.

#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>

int
main (void)
{
  printf("%g\n", strtof("0.0", NULL));
  printf("%g\n", strtod("0.0", NULL));
  printf("%Lg\n", strtold("0.0", NULL));
  printf("%g\n", strtof("0", NULL));
  printf("%g\n", strtod("0", NULL));
  printf("%Lg\n", strtold("0", NULL));
  printf("%g\n", strtof("0.000", NULL));
  printf("%g\n", strtod("0.000", NULL));
  printf("%Lg\n", strtold("0.000", NULL));
  printf("%g\n", strtof("0.000e0", NULL));
  printf("%g\n", strtod("0.000e0", NULL));
  printf("%Lg\n", strtold("0.000e0", NULL));
  return 0;
}

prints just 0s.

------- Additional Comment #2 From Pete Eberlein 2008-04-29 19:29 -------
Bah, close this due to user error.  I neglected to include stdlib.h.

Aside: I discovered the problem reading the null terminator while working on the
dfp version and assumed it affected the bfp version as well.  It looks like
str_to_mpn isn't affected by the null so it just works.

------- Additional Comment #3 From Jakub Jelinek 2008-04-29 19:43 -------
Invalid.

     Query page      Enter new bug
Actions: New | Query | bug # | Reports | Requests   New Account | Log In