Re: strtod ("nan") returns negative NaN

2018-08-20 Thread Brian Inglis
On 2018-08-14 13:24, Achim Gratz wrote: > Corinna Vinschen writes: >> With your patch, strtold looks more correct, but it still prints the >> sign of NaN: >> >> strtod ("nan", NULL) = nan >> strtod ("-nan", NULL) = nan >> strtold ("nan", NULL) = nan >> strtold ("-nan", NULL) = -nan >>

Re: strtod ("nan") returns negative NaN

2018-08-20 Thread Brian Inglis
On 2018-08-14 15:44, Eric Blake wrote: > On 08/14/2018 04:31 PM, Stephen John Smoogen wrote: >>> The C standard disagrees with you [ISO:IEC 9899:2011, section 5.2.4.2.2]: >>> "An implementation may give zero and values that are not floating-point >>> numbers (such as infinities and NaNs) a sign or

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Masamichi Hosoda
cf4a20e0773f4a38d6d56b0867fe3725859e5e Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Tue, 14 Aug 2018 22:29:34 +0900 Subject: [PATCH v2 1/2] Fix strtod ("nan") returns negative NaN The definition of qNaN for x86_64 and i386 was wrong. So strtod ("nan") and strtold (&qu

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Steven Penny
On Tue, 14 Aug 2018 16:44:59, Eric Blake wrote: The remaining question is whether it should turn "-NaN" into -NaN; and the argument that glibc JUST fixed their bug 23007 to make strtod("-nan") return -NaN means that Cygwin should, indeed, preserve the negative sign bit when parsing "-nan".

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Eric Blake
On 08/14/2018 04:31 PM, Stephen John Smoogen wrote: The C standard disagrees with you [ISO:IEC 9899:2011, section 5.2.4.2.2]: "An implementation may give zero and values that are not floating-point numbers (such as infinities and NaNs) a sign or may leave them unsigned. Wherever such values

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Stephen John Smoogen
On Tue, 14 Aug 2018 at 17:09, Andy Moreton wrote: > > On Tue 14 Aug 2018, Steven Penny wrote: > > a number can be positive or negative. as "NaN" is by definition not a > > number, > > it cannot be positive or negative, it is simply itself, something anathema > > to > > a number. > > The C

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Andy Moreton
On Tue 14 Aug 2018, Steven Penny wrote: > a number can be positive or negative. as "NaN" is by definition not a number, > it cannot be positive or negative, it is simply itself, something anathema to > a number. The C standard disagrees with you [ISO:IEC 9899:2011, section 5.2.4.2.2]: "An

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Joseph Myers
On Wed, 15 Aug 2018, Masamichi Hosoda wrote: > On Linux with glibc, both strtod ("nan") > and strtod ("-nan") return positive NaN. > > So I've created the patch that behaves like glibc. > Both strtod ("nan") and strtod ("-nan") return positive NaN. I would suggest that you should not consider

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Achim Gratz
Corinna Vinschen writes: > With your patch, strtold looks more correct, but it still prints the > sign of NaN: > > strtod ("nan", NULL) = nan > strtod ("-nan", NULL) = nan > strtold ("nan", NULL) = nan > strtold ("-nan", NULL) = -nan > nan ("") = nan > > Question: What's wrong with that?

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Steven Penny
On Tue, 14 Aug 2018 15:23:01, Corinna Vinschen wrote: I just wonder why returning -NaN when the input is "-nan" isn't the better approach. After all: printf ("nan (\"\") =3D %f\n", nan ("")); printf ("-nan (\"\") =3D %f\n", -nan ("")); =3D=3D> nan ("") =3D nan -nan ("") =3D -nan So,

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Heavenly Avenger
Well, that's what I get in linux and cygwin for: #include #include #include /* the last two printfs requires this */ int main (void) {   printf ("strtof (\"nan\", NULL) = %f\n", strtof ("nan", NULL));   printf ("strtof (\"-nan\", NULL) = %f\n", strtof ("-nan", NULL));   printf ("strtod

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Masamichi Hosoda
strtold sets sign bit when parameter has '-' character. >> The wrong long double NaN definition is negative NaN that is set sign bit. >> So without my patch, both strtold ("nan") and >> strtold ("-nan") return negative NaN. >> >> On the other hand, str

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Corinna Vinschen
On Aug 14 12:20, Heavenly Avenger wrote: > On 8/14/2018 10:23 AM, Corinna Vinschen wrote: > > I just wonder why returning -NaN when the input is "-nan" isn't the > > better approach. After all: > > > >printf ("nan (\"\") = %f\n", nan ("")); > >printf ("-nan (\"\") = %f\n", -nan ("")); >

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Heavenly Avenger
) = nan strtod ("nan", NULL) = nan strtod ("-nan", NULL) = nan strtold ("nan", NULL) = nan strtold ("-nan", NULL) = nan This further supports the reasoning to always return just 'nan'. On 8/14/2018 12:05 PM, Masamichi Hosoda wrote: Hi I've found that

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Heavenly Avenger
negative NaN. On the other hand, strtod inverts the sign when parameter has '-' character. The wrong double NaN definition is negative NaN. So without my patch, strtod ("nan") returns negative NaN and strtod ("-nan") returns positive NaN. Your patch improves the situation, th

strtod ("nan") returns negative NaN

2018-08-14 Thread Masamichi Hosoda
Hi I've found that strtod ("nan") returns negative NaN on Cygwin 64 bit. https://cygwin.com/ml/cygwin/2018-08/msg00168.html On Linux with glibc, both strtod ("nan") and strtod ("-nan") return positive NaN. So I've created the patch that behaves like glibc. Both st

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Stephen John Smoogen
at? Wouldn't it be more correct if > > > strtod returns -NaN for "-nan" as well? > > > > In my investigate, > > strtold sets sign bit when parameter has '-' character. > > The wrong long double NaN definition is negative NaN that is set sign bit. > &g

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Corinna Vinschen
n > > nan ("") = nan > > > > Question: What's wrong with that? Wouldn't it be more correct if > > strtod returns -NaN for "-nan" as well? > > In my investigate, > strtold sets sign bit when parameter has '-' character. > The wrong long doubl

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Masamichi Hosoda
strtod ("-nan", NULL) = nan > strtold ("nan", NULL) = nan > strtold ("-nan", NULL) = -nan > nan ("") = nan > > Question: What's wrong with that? Wouldn't it be more correct if > strtod returns -NaN for "-nan" as well? In my inv

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Corinna Vinschen
On Aug 14 11:56, Corinna Vinschen wrote: > On Aug 14 13:45, Masamichi Hosoda wrote: > > >From a50ee5a4747a99c70469a53fe959f3dc22d3b79a Mon Sep 17 00:00:00 2001 > > From: Masamichi Hosoda > > Date: Tue, 14 Aug 2018 12:50:32 +0900 > > Subject: [PATCH] Fix strtod ("nan") returns qNaN > > > > The

Re: strtod ("nan") returns negative NaN

2018-08-14 Thread Corinna Vinschen
On Aug 14 13:45, Masamichi Hosoda wrote: > >From a50ee5a4747a99c70469a53fe959f3dc22d3b79a Mon Sep 17 00:00:00 2001 > From: Masamichi Hosoda > Date: Tue, 14 Aug 2018 12:50:32 +0900 > Subject: [PATCH] Fix strtod ("nan") returns qNaN > > The definition of qNaN for x86_64 and x86 was wrong. > So

Re: strtod ("nan") returns negative NaN

2018-08-13 Thread Masamichi Hosoda
>>> On Mon, 13 Aug 2018 at 19:46, Duncan Roe wrote: On Mon, Aug 13, 2018 at 12:52:48PM -0400, Stephen John Smoogen wrote: > On Mon, 13 Aug 2018 at 11:16, Masamichi Hosoda > wrote: [...] > On Fedora 27 with 7.3.1 it gives > ``` > stod ("nan") = nan >

Re: strtod ("nan") returns negative NaN

2018-08-13 Thread Steven Penny
On Tue, 14 Aug 2018 11:31:35, Masamichi Hosoda wrote: If I understand correctly, `std::stod ()` uses cygwin1.dll's `strtod ()` for the conversion. `std::stod ()` is defined in /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h L6388-. It calls `__gnu_cxx::__stoa ()` with

strtod ("nan") returns negative NaN (was `std::stod ("nan")` returns negative NaN)

2018-08-13 Thread Masamichi Hosoda
>> On Mon, 13 Aug 2018 at 19:46, Duncan Roe wrote: >>> >>> On Mon, Aug 13, 2018 at 12:52:48PM -0400, Stephen John Smoogen wrote: >>> > On Mon, 13 Aug 2018 at 11:16, Masamichi Hosoda >>> > wrote: >>> [...] >>> > On Fedora 27 with 7.3.1 it gives >>> > ``` >>> > stod ("nan") = nan >>> > stod