delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/08/14/08:18:19

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:date:message-id:to:cc:subject:from:in-reply-to
:references:mime-version:content-type:content-transfer-encoding;
q=dns; s=default; b=rqky2lWMhRMJBP07uxd8QvMRiv7C2otSBs9hEmC3Zs8
GmFWMPQwYQzYVFbUJiWEHpjhVWNo5qGHIi3XlZwgLHHuW5xpCJPqRipFaXFMtJlA
uDjKPbrXlNeinokv2JLHPq/phOLrxkmYvv1gf9ffBs52mE57awy64Su02Rt+X1rg
=
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:date:message-id:to:cc:subject:from:in-reply-to
:references:mime-version:content-type:content-transfer-encoding;
s=default; bh=p4gOp55A0sQjjyksfeyLQrBFVW8=; b=awe1+WgCDcYXPQm1e
0FpHQMTGsWvchYOeXpHzDXEF6X2NaisF/Q1Qk2R56JeT59nc6rWR0R9TUsRNUfgm
HJiAr2F0qmR5T/w8Q11LF5Yxit9D8GUDN+Ea2ws+lKmQiMvWKis8dIXAZ8P63OE4
BSky2sK645MQgdxGl4RVUOVR2E=
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=-10.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=H*c:Text, H*Ad:D*jp
X-HELO: msc13.plala.or.jp
Date: Tue, 14 Aug 2018 21:17:57 +0900 (JST)
Message-Id: <20180814.211757.2066454831159853501.trueroad@trueroad.jp>
To: cygwin AT cygwin DOT com
Cc: trueroad AT trueroad DOT jp
Subject: Re: strtod ("nan") returns negative NaN
From: Masamichi Hosoda <trueroad AT trueroad DOT jp>
In-Reply-To: <20180814103900.GU3747@calimero.vinschen.de>
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>
Mime-Version: 1.0
X-VirusScan: Outbound; mvir-ac13; Tue, 14 Aug 2018 21:18:03 +0900

> 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(-)
>> 
>> Can you please send this patch to the newlib AT sourceware DOT org
>> mailing list?  As soon as something in newlib gets changed, a lot of
>> other targets are affected and the guys working on those targets should
>> have a chance to chime in.

I'll improve the patch and send it.
It did not consider environments excluding x86 and x86_64.

> Looks like strtold is affected as well, just differently:
> 
>   printf ("strtod (\"nan\", NULL) = %f\n", strtod ("nan", NULL));
>   printf ("strtod (\"-nan\", NULL) = %f\n", strtod ("-nan", NULL));
>   printf ("strtold (\"nan\", NULL) = %Lf\n", strtold ("nan", NULL));
>   printf ("strtold (\"-nan\", NULL) = %Lf\n", strtold ("-nan", NULL));
>   printf ("nan (\"\") = %f\n", nan (""));
> 
> ==>
> 
>   strtod ("nan", NULL) = -nan
>   strtod ("-nan", NULL) = nan
>   strtold ("nan", NULL) = -nan
>   strtold ("-nan", NULL) = -nan
>   nan ("") = nan
> 
> so it prints always -nan.
> 
> 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.

My previous patch removes the sign inversion in strtod when NaN.
But I did not fix strtold.

Perhaps, the following patch removes the sign bit setting of strtold when NaN.

```
--- a/newlib/libc/stdlib/strtodg.c
+++ b/newlib/libc/stdlib/strtodg.c
@@ -585,6 +585,7 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp,
 					if (*s == '(') /*)*/
 						irv = hexnan(&s, fpi, bits);
 #endif
+					sign = 0;
 					goto infnanexp;
 					}
 			  }
```

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