delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/08/14/11:21:48

X-Recipient: archive-cygwin AT delorie DOT 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:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=vbd+PooVzrIbXDKO
16TJ5VP1c2syprM/Pzdq4hvZ+W98A0byZKwZq4gBKc7s1QC+774BJpKcdAlM/3fP
bQzRSFu14aq0J/7Cc4DanCTdU3FRQpVRzf5BvXPWdoNWrXwXicaU/kUTmZzn0URg
cRdl0A99uj/FSC9RpKMC7ue/77M=
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:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=MBXeUk8BTOcE1KALa81T91
YkX1E=; b=A7UxEMYA9A2Pbnx2LyCTvVMta7jcWaGRfFQe2fcQ5DyATFV89Ei/q6
1DVwEFPe7HTfNuuzGqrbL3D2nAqXqR/0FYhvoi56ik85Pf3ngS7eWPRDQGB5eimg
dXArGRWniZpcDdEgP9g6yY7tj3P151qYhcYspSBC/wmOR+T8GOcLU=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:D*ws
X-HELO: mail.avenger.ws
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=avenger.ws; s=ethereal; t=1534260073; bh=eNUaRFmE36IW1iddwm+iH0zKL11XH4XBxBjVUNya49c=; h=Subject:To:References:From:Date:In-Reply-To; b=6b3zqeTexj+S401sleQeGnTUI8qRIDY37EJEFQpB7UCNOUyNa1Eh8wTNhHYSF5OrH HNU4oksmY7FFhDtBDxSdv9XLuIQ60F5ppKBoUEdxilw+6ce1W8A7ceUojwGP24ZeTM bA9pvYcTBpbMnyWANY6kA7NbVWMGixNrvG5e4cgQ=
Subject: Re: strtod ("nan") returns negative NaN
To: cygwin AT cygwin DOT com
References: <20180814095618 DOT GT3747 AT calimero DOT vinschen DOT de> <20180814095618_dot_GT3747_at_calimero_dot_vinschen_dot_de> <20180814103900 DOT GU3747 AT calimero DOT vinschen DOT de> <20180814 DOT 211757 DOT 2066454831159853501 DOT trueroad AT trueroad DOT jp> <20180814132301 DOT GX3747 AT calimero DOT vinschen DOT de>
From: Heavenly Avenger <avenger AT avenger DOT ws>
Message-ID: <1e04c237-70f8-5cc9-7dae-d00e3bfea39d@avenger.ws>
Date: Tue, 14 Aug 2018 12:20:56 -0300
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
MIME-Version: 1.0
In-Reply-To: <20180814132301.GX3747@calimero.vinschen.de>
X-IsSubscribed: yes

On 8/14/2018 10:23 AM, Corinna Vinschen 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 AT trueroad DOT 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
>
> ?
>
> Corinna
>
I'd say it is not the better/best approach as, even though it makes 
sense, all other implementations or linux distributions treat it as a 
plain "nan". So anything written for linux will potentially break on 
cygwin, I am not sure this is the idea behind cygwin, right?

Besides, it only adds complexity when checking for nans, if string 
comparison is relied upon, as an additional character may show up.

As NaN is essentially not a number, what is not a number can't be said 
as positive or negative. Then we get to a whole philosophical level. It 
can, but we can't guarantee a cow (which is not a number) can be seen 
with a "positive cow". A mood (which is not a number), can be seen as 
positive or negative. Yet it will depend on your concept of a positive 
or negative mood... so... well, better not leave the algebra sign to 
this. As 0 is equal to -0. Does -0 exist? :)

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019