This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

Re: [PATCH] Fix strtod for small DBL_DIG


On May 16, 2011, at 7:36 AM, Corinna Vinschen wrote:

> 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.
> 

Not sure but I found they match if you test identical numbers.
12.3456789 is closer to 12.3456792
as
12.2345678 is closer to 12.3456783
so not sure what is up???
strtof and strtod should find the closest representable value? yes?
Steve



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