X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:mime-version:references:in-reply-to:from:date
	:message-id:subject:to:content-type; q=dns; s=default; b=MoOM092
	8l2eFBXRqwFexub5/vgxzOxLqkktklhVkWV0Jh8j+TLIiJSd09YIBrCY8m9M7eIA
	lqCoymuUitEGIV5zQrKi+6Tdp9rxPI5GMVguERBV0UW5lekeVYqeZ6YRvuCFp+4I
	ElCSgYH1t26PDqHIJTE2aNRtlWdw+zY4jc6U=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:mime-version:references:in-reply-to:from:date
	:message-id:subject:to:content-type; s=default; bh=Xm59AZJ5gxIcP
	cP3m8crNjuqqPo=; b=wl1waJgSJctUFCXVVb0ClN7j9ja5T2BIDsZAUWrrJEKJo
	QaYt8n3EjXOgV6bhmeI/mIa1Mxzq59qPuRBGdUpVkEZ4smhGUSwpBfmnbb0KAIG1
	dLw95aCCzHlRbo7bzLX7AocuHAQXAU39zB9C8veDDr8+AWnig4EQMgCjBMVDEM=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:sk:x5-v6so, Hx-spam-relays-external:209.85.215.196, H*RU:209.85.215.196, emails
X-HELO: mail-pg1-f196.google.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com; s=20161025;        h=mime-version:references:in-reply-to:from:date:message-id:subject:to;        bh=vte4hXcpaqLYh9DoJRPnFmbki/wmJ3Ab7DiC1ZqCwdU=;        b=nqD7yklbm2zjdMxMa0PjW3Th6mt4Smf2JjX+xWw1APTWMBdTWoAVvxN69kLYCjnGcV         WqiB4aivYoSUOrM8WaRR0uQPorEGFmRUQ1eBhtxlHkFSg9ABTeQawbEkr9yYB8U7uHV6         R7D6XHtfsPfcY4A0XXHoM0lDsqtxhFep23MS1pzeF8DOuNLurFHRsjOcIZfhT6AvtjWs         E+NHt4UIGnyrJYrUhpRigyuNpFvop2EmaDdEOdnFaFrQKYv00zlQTEp0GMk8gtmFCif3         prE4c5jnvHHcn3UroosswK9O5//qbzbOUD1YdaBhxXcUIN0u7VKDLJMfvdnNmZbA+Ny/         wU3A==
MIME-Version: 1.0
References: <20180814095618.GT3747@calimero.vinschen.de> <20180814103900.GU3747@calimero.vinschen.de> <20180814.211757.2066454831159853501.trueroad@trueroad.jp> <20180814132301.GX3747@calimero.vinschen.de>
In-Reply-To: <20180814132301.GX3747@calimero.vinschen.de>
From: Stephen John Smoogen <smooge@gmail.com>
Date: Tue, 14 Aug 2018 09:41:00 -0400
Message-ID: <CANnLRdiJ-SToxuT29sB9gi7VfyZMg3wWeSQ2hkyv280WD7L8-g@mail.gmail.com>
Subject: Re: strtod ("nan") returns negative NaN
To: cygwin@cygwin.com
Content-Type: text/plain; charset="UTF-8"
X-IsSubscribed: yes

On Tue, 14 Aug 2018 at 09:23, Corinna Vinschen
<corinna-cygwin@cygwin.com> wrote:
>
> On Aug 14 21:17, Masamichi Hosoda wrote:
> > > 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 <trueroad@trueroad.jp>
> > >> > 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 strtod ("nan") returned sNaN instead of qNaN.
> > >> >
> > >> > Furthermore, it was inverted the sign bit with the presence of `-` character.
> > >> > So strtod ("-nan") returned qNaN.
> > >> >
> > >> > This commit fixes definition of qNaN
> > >> > and removes the sign bit inversion when evaluating "nan".
> > >> > ---
> > >> >  newlib/libc/stdlib/gd_qnan.h | 8 ++++----
> > >> >  newlib/libc/stdlib/strtod.c  | 1 +
> > >> >  2 files changed, 5 insertions(+), 4 deletions(-)
> > >> [...]
> > > 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?  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.
> > So without my patch, both strtold ("nan") and
> > strtold ("-nan") return 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, that's a sure thing and I did not
> question that.
>
> 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 (""));
>
> ==>
>
>   nan ("") = nan
>   -nan ("") = -nan
>
> So, shouldn't the ideal outcome be this:
>
>   strtod ("nan", NULL) = nan
>   strtod ("-nan", NULL) = -nan
>   strtold ("nan", NULL) = nan
>   strtold ("-nan", NULL) = -nan
>
> ?

This is going off some old memories from dealing with this looong ago
with Linux. I think that is set in the IEEE standard where there is
only a NaN and it is neither negative or positive.. it is just NaN.
While Negative NaN is possible, it is implementation defined and most
implementations seem to now default to the if you see -nan 'something
weird has happened'. I don't have access to the emails where this came
up years ago.. so I found these which might help

https://en.wikipedia.org/wiki/IEEE_754
https://en.wikipedia.org/wiki/NaN
http://www.cplusplus.com/forum/general/73201/



-- 
Stephen J Smoogen.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

