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: Bug in Cygwin strtod()


Humm, I understand why I didn't consider this as a failure,

Here is what I got.

using
value = strtod("2.30258509299404568402", 0);

with my patch:

generate strtod - value: 2.302585092994045.
expected strtod - value: 2.302585092994046.

without my patch (after your revert)

generate strtod - value: 2.302585092994046.
expected strtod - value: 2.302585092994046.

I thought that no rounding was necessary, but reading 7.20.1.3.9 it is
clearly said that the result should be correctly rounded.

So this is a rounding bug with my patch indeed, that I'd like to fix.
Since reverting my patch totally messes up the __DBL_DIG__ == 6 targets.

I'll let you know,

Christian


On 12/19/2012 11:16 AM, Corinna Vinschen wrote:
> Here's an error report w/ replies on the Cygwin list:
> 
> On Dec 19 08:03, marco atzeri wrote:
>> On 12/19/2012 2:30 AM, KHMan wrote:
>>> On 12/19/2012 8:54 AM, Cary R. wrote:
>>>> The following code demonstrates a subtle bug in the Cygwin version of
>>>> strtod(). The value it generates is slightly different than the value
>>>> when using the math header files. This used to work correctly some
>>>> time ago (months). I just took the time to track the problem down in
>>>> our regression suite.
>>>>
>>>> #include<math.h>
>>>> #include<stdio.h>
>>>> #include<stdlib.h>
>>>>
>>>> int main()
>>>> {
>>>>     double value = M_LN10;
>>>>
>>>>     printf("generate const. - value: %0.15f.\n", value);
>>>>     printf("expected const. - value: 2.302585092994046.\n");
>>>>
>>>>     printf("\n");
>>>>     value = strtod("2.30258509299404568402", 0);
>>>>
>>>>     /* Note: the last digit is incorrect. */
>>>>     printf("generate strtod - value: %0.15f.\n", value);
>>>>     printf("expected strtod - value: 2.302585092994046.\n");
>>>>
>>>>     return 0;
>>>> }
>>>
>>> Yep, looks like the significand misses its mark by 1.
>>>
>>
>> strtod is from newlib.
>> the last change in the code is one year and half ago
>>
>> http://sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/stdlib/strtod.c.diff?r1=1.17&r2=1.18&cvsroot=src
> 
> In fact, the aforementioned change is the culprit of the wrong
> result.  The discussion about the patch starts here:
> http://sourceware.org/ml/newlib/2011/msg00178.html
> 
> For now I have reverted the patch.  It might have fixed some problem,
> but it introduced a new one, so it was apparently not correct, and I
> was not able to reproduce the described problem in the first place.
> 
> 
> Corinna
> 


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