Bug#260377: libc6: strtold() fail on number with many fraction digits
Package: libc6
Version: 2.3.2.ds1-13
I came across a bug report on the glibc-bug mailing list, and decided
to test the example code in Debian/Unstable. IT seem to fail there
too, so I guess the problem isn't fixed in glibc yet.
This is the output from the program:
String '42.0000000000000000001' converts to long double 42.00000000000000000000
String '42.00000000000000000001' converts to long double 0.00000000000000000000
String '42.0000000000000000000001' converts to long double 0.00000000000000000000
I expected the last two conversions to end up as 42.0, not 0.0. Am I
mistaken?
Here is the source.
/*
* Demonstrate bug in strtold() in glibc. The last two number strings
* converts to 0, not 42 as it should.
* Based on code from Ivano Primi and modified by Petter Reinholdtsen.
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
extern int errno;
extern long double strtold(const char *nptr, char **endptr);
int main (void)
{
char *numbers[] = {
"42.0000000000000000001",
"42.00000000000000000001",
"42.0000000000000000000001",
};
char* endptr;
long double x;
int i;
errno = 0;
for (i = 0; i < 3; i++) {
x = strtold (numbers[i], &endptr);
if ( endptr == numbers[i] && x == 0 )
{
fprintf (stderr, " *** Unagreable input\n");
return 1;
}
else if ( errno != 0 )
{
if ( x == 0 )
fprintf (stderr, " *** Underflow\n");
else
fprintf (stderr, " *** Overflow\n");
return 2;
}
else
{
printf ("String '%s' converts to long double %.20Lf\n", numbers[i], x);
}
}
return 0;
}
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.26-1-686
Locale: LANG=C, LC_CTYPE=C
Versions of packages libc6 depends on:
ii libdb1-compat 2.1.3-7 The Berkeley database routines [gl
-- no debconf information
Reply to: