delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/08/14/20:02:53

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=b9j9AxNPcn1rQXdSRTm9+Si2uYIGrQqlbKcHANOKaUJ
dvt6L1Q00bQeaA2+NKWS7pG3kuiSy84zrCjGWcdDqm07+J3C6dqU6Ppyoj5CUSG8
Og7y/xUoSPS2sqYs7GRBhVOB/ceAKCLRKOSMI+60cM2CWGzaopG6eHxf4/o8eMZk
=
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=54bkQEnzuSWwY9NEHp5YzYEFE30=; b=G3FrEMEASRGm/GzeA
P6H4ENhAsWSBxE5kEgeHQY6EKTfEQWxbe0+c07EGJBp3OOGGmCUhgIltiq1++3Os
0xDLSn9C78WsPfm8vz7GLiozCZGNgCWJa1Kj8fXPDOeSFyXn+QJa+bbOL7o73Xlj
Z9k1uhd6lwCaFgA/FKy7GEQKHk=
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
Delivered-To: corinna-cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=Hx-languages-length:3731, H*c:PHrt
X-HELO: msc14.plala.or.jp
Date: Wed, 15 Aug 2018 09:02:02 +0900 (JST)
Message-Id: <20180815.090202.1093518487238961077.trueroad@trueroad.jp>
To: newlib AT sourceware DOT org, cygwin AT cygwin DOT com, joseph AT codesourcery DOT com
Cc: corinna-cygwin AT cygwin DOT com, trueroad AT trueroad DOT jp
Subject: Re: strtod ("nan") returns negative NaN
From: Masamichi Hosoda <trueroad AT trueroad DOT jp>
In-Reply-To: <alpine.DEB.2.20.1808141943140.21830@digraph.polyomino.org.uk>
References: <20180814095618 DOT GT3747 AT calimero DOT vinschen DOT de> <20180815 DOT 000539 DOT 1012490218433540835 DOT trueroad AT trueroad DOT jp> <alpine DOT DEB DOT 2 DOT 20 DOT 1808141943140 DOT 21830 AT digraph DOT polyomino DOT org DOT uk>
Mime-Version: 1.0
X-VirusScan: Outbound; mvir-ac14; Wed, 15 Aug 2018 09:02:05 +0900

----Next_Part(Wed_Aug_15_09_02_02_2018_289)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

> 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 fixed bugs in glibc (bug 
> 23007 in this case) to be appropriate to emulate in other libraries.

I've create the patch that behaves to preserve the sign bit.

The result on Cygwin 64 bit (newlib, x86_64) with the patch:
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = -nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = -nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = -nan
```

Thank you for your suggestion.

----Next_Part(Wed_Aug_15_09_02_02_2018_289)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v2-0001-Fix-strtod-nan-returns-negative-NaN.patch"

From 91cf4a20e0773f4a38d6d56b0867fe3725859e5e Mon Sep 17 00:00:00 2001
From: Masamichi Hosoda <trueroad AT trueroad DOT jp>
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 ("nan") returned negative NaN
instead of positive NaN.

strtof ("nan") returns positive NaN so it does not have this issue.

This commit fixes definition of qNaN for x86_64 and i386.
So strtod ("nan") and strtold ("nan") return positive NaN.
---
 newlib/libc/stdlib/gd_qnan.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/newlib/libc/stdlib/gd_qnan.h b/newlib/libc/stdlib/gd_qnan.h
index b775f82..8b0726a 100644
--- a/newlib/libc/stdlib/gd_qnan.h
+++ b/newlib/libc/stdlib/gd_qnan.h
@@ -26,6 +26,20 @@
 #elif defined(__IEEE_LITTLE_ENDIAN)
 
 #if !defined(__mips)
+#if defined (__x86_64__) || defined (__i386__)
+#define f_QNAN 0x7fc00000
+#define d_QNAN0 0x0
+#define d_QNAN1 0x7ff80000
+#define ld_QNAN0 0x0
+#define ld_QNAN1 0xc0000000
+#define ld_QNAN2 0x7fff
+#define ld_QNAN3 0x0
+#define ldus_QNAN0 0x0
+#define ldus_QNAN1 0x0
+#define ldus_QNAN2 0x0
+#define ldus_QNAN3 0xc000
+#define ldus_QNAN4 0x7fff
+#else
 #define f_QNAN 0xffc00000
 #define d_QNAN0 0x0
 #define d_QNAN1 0xfff80000
@@ -38,6 +52,7 @@
 #define ldus_QNAN2 0x0
 #define ldus_QNAN3 0xc000
 #define ldus_QNAN4 0xffff
+#endif
 #elif defined(__mips_nan2008)
 #define f_QNAN 0x7fc00000
 #define d_QNAN0 0x0
-- 
2.17.0


----Next_Part(Wed_Aug_15_09_02_02_2018_289)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v2-0002-Fix-strtof-nan-returns-positive-NaN.patch"

From 51363ce08ffc587b206f2efdd72527ffba7b4381 Mon Sep 17 00:00:00 2001
From: Masamichi Hosoda <trueroad AT trueroad DOT jp>
Date: Wed, 15 Aug 2018 08:39:22 +0900
Subject: [PATCH v2 2/2] Fix strtof ("-nan") returns positive NaN

strtof ("-nan") returned positive NaN instead of negative NaN.
strtod ("-nan") and strtold ("-nan") return negative NaN.

Linux glibc has been fixed
that strto{f|d|ld} ("-nan") returns negative NaN.
https://sourceware.org/bugzilla/show_bug.cgi?id=23007

This commit makes strtof preserves the negative sign bit
when parsing "-nan" like glibc.
---
 newlib/libc/stdlib/strtod.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c
index 0cfa9e6..9c5ed56 100644
--- a/newlib/libc/stdlib/strtod.c
+++ b/newlib/libc/stdlib/strtod.c
@@ -1285,7 +1285,7 @@ strtof_l (const char *__restrict s00, char **__restrict se, locale_t loc)
 {
   double val = _strtod_l (_REENT, s00, se, loc);
   if (isnan (val))
-    return nanf (NULL);
+    return signbit (val) ? -nanf (NULL) : nanf (NULL);
   float retval = (float) val;
 #ifndef NO_ERRNO
   if (isinf (retval) && !isinf (val))
@@ -1300,7 +1300,7 @@ strtof (const char *__restrict s00,
 {
   double val = _strtod_l (_REENT, s00, se, __get_current_locale ());
   if (isnan (val))
-    return nanf (NULL);
+    return signbit (val) ? -nanf (NULL) : nanf (NULL);
   float retval = (float) val;
 #ifndef NO_ERRNO
   if (isinf (retval) && !isinf (val))
-- 
2.17.0



----Next_Part(Wed_Aug_15_09_02_02_2018_289)--
Content-Type: text/plain; charset=us-ascii


--
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
----Next_Part(Wed_Aug_15_09_02_02_2018_289)----

- Raw text -


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