From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21142 invoked by alias); 15 Aug 2018 00:02:13 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 21101 invoked by uid 9078); 15 Aug 2018 00:02:10 -0000 Received: (qmail 21083 invoked by uid 89); 15 Aug 2018 00:02:10 -0000 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 Received: from msc14.plala.or.jp (HELO msc14.plala.or.jp) (60.36.166.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Aug 2018 00:02:08 +0000 Received: from localhost ([223.217.20.9]) by msc14.plala.or.jp with ESMTP id <20180815000205.NKJD8002.msc14.plala.or.jp@localhost>; Wed, 15 Aug 2018 09:02:05 +0900 Date: Wed, 15 Aug 2018 12:55:00 -0000 Message-ID: <20180815.090202.1093518487238961077.trueroad@trueroad.jp> To: newlib@sourceware.org, cygwin@cygwin.com, joseph@codesourcery.com Cc: corinna-cygwin@cygwin.com, trueroad@trueroad.jp Subject: Re: strtod ("nan") returns negative NaN From: Masamichi Hosoda In-Reply-To: References: <20180814095618.GT3747@calimero.vinschen.de> <20180815.000539.1012490218433540835.trueroad@trueroad.jp> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Aug_15_09_02_02_2018_289)--" Content-Transfer-Encoding: 7bit X-VirusScan: Outbound; mvir-ac14; Wed, 15 Aug 2018 09:02:05 +0900 X-SW-Source: 2018-08/txt/msg00198.txt.bz2 Message-ID: <20180815125500.3KpzVIz50N1MfPCHhba5RZzeeX2s2KxHuyZP3TUWSKg@z> ----Next_Part(Wed_Aug_15_09_02_02_2018_289)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-length: 741 > 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" Content-length: 1516 >From 91cf4a20e0773f4a38d6d56b0867fe3725859e5e 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 ("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" Content-length: 1497 >From 51363ce08ffc587b206f2efdd72527ffba7b4381 Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda 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 Content-length: 219 -- 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)----