This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Fix strtod for small DBL_DIG
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Mon, 16 May 2011 13:36:18 +0200
- Subject: Re: [PATCH] Fix strtod for small DBL_DIG
- References: <4DCBD202.3030100@st.com>
- Reply-to: newlib at sourceware dot org
Hi Christian,
On May 12 14:26, Christian Bruel wrote:
> Hello,
>
> This fixes a Plummhall ch7_1961B test failure discovered on SH4 GCC
> for -m4-single-only mode (doubles as 32 bit floats) on sscanf.
>
> It is better illustrated with the attached reduced test case. The
> problem turned out to be the digit counts in _strtod_ that are
> incremented to much beyond DBL_DIG.
>
> The attached patch fixes this problem by updating the counts after
> the DBL_DIG checks.
> [...]
> #include <stdlib.h>
>
> double Dval1 = 12.345678;
>
> main()
> {
> double dtmp;
> char *buf;
> dtmp = strtod ("12.3456789", &buf);
>
> if (dtmp != Dval1)
> abort();
>
> return 0;
>
> }
For testing I changed double to float and strtod to strtof to get a 32
bit value on 32 bit Cygwin and 64 bit Linux.
This code always aborts because the value 12.345678 is not representable
as 32 bit float value. The same happens when using glibc as well. If
you print the float values with many digits, you get something like
12.34567832946777 for DVal1 and
12.34567928314209 for dtmp.
on both, Cygwin/newlib and Linux/glibc.
Also, this does *not* change if I use your patch.
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat