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=C7MDRlDW3F63xxcpeaM8nu5l/77VIylAMJFz58hdO4r cFpa9bTVDBmVdt+fdswe20u0G/H7D8tCNSiMnDLDbZCw1g9rZNDeQw17M87vennN VBwhYmwBJVDu67gINA4tNrly7FmNUnAijXNL2DJOKGKnEEeswA+j7UYOI0wuvFzY = 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=VmbYzX5MbPlrYyL9S99pR+U5ydY=; b=fVdRTlfMQZ1fcuR2z IhuYjruu1LPSverSQs/HPmCCiLAsMFjrrAmANXn0aWBtSXW5nCIwhX2Mf276+zcB TU56KDg5K8pNq5lB73Y1XLiBGS+IhsbrHX/y1kPWXfMPZotYYye6TFKor6V1Zq74 YZmu+K4q5MxuUPmSCxycrYKDNk= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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=-23.4 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=4516, H*UA:version, H*x:version, inversion X-HELO: msc14.plala.or.jp Date: Tue, 14 Aug 2018 13:45:27 +0900 (JST) Message-Id: <20180814.134527.917341694729989717.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 In-Reply-To: <20180814.113135.1571893395887584078.trueroad@trueroad.jp> References: <20180814 DOT 100952 DOT 1684125661222835312 DOT trueroad AT trueroad DOT jp> <20180814 DOT 113135 DOT 1571893395887584078 DOT trueroad AT trueroad DOT jp> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Tue_Aug_14_13_45_27_2018_543)--" Content-Transfer-Encoding: 7bit X-VirusScan: Outbound; mvir-ac14; Tue, 14 Aug 2018 13:45:36 +0900 ----Next_Part(Tue_Aug_14_13_45_27_2018_543)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit >>> On Mon, 13 Aug 2018 at 19:46, Duncan Roe wrote: >>>> >>>> On Mon, Aug 13, 2018 at 12:52:48PM -0400, Stephen John Smoogen wrote: >>>> > On Mon, 13 Aug 2018 at 11:16, Masamichi Hosoda wrote: >>>> [...] >>>> > On Fedora 27 with 7.3.1 it gives >>>> > ``` >>>> > stod ("nan") = nan >>>> > stod ("-nan") = nan >>>> > quiet_NaN () = nan >>>> > ``` [...] >> Cygwin 2.10.0 64 bit with gcc 7.3.0 >> ``` >> strtod ("nan", NULL) = -nan >> strtod ("-nan", NULL) = nan >> nan ("") = nan >> ``` >> >> Ubuntu 16.04 LTS 64 bit with gcc 5.4.0 >> ``` >> strtod ("nan", NULL) = nan >> strtod ("-nan", NULL) = nan >> nan ("") = nan >> ``` I've created the quick hack patch that fixes `strtod ()`. On Cygwin 64 bit with the patch, result of foobar.c: ``` strtod ("nan", NULL) = nan strtod ("-nan", NULL) = nan nan ("") = nan ``` Also result of foobar.cc: ``` stod ("nan") = nan stod ("-nan") = nan quiet_NaN () = nan ``` ----Next_Part(Tue_Aug_14_13_45_27_2018_543)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-Fix-strtod-nan-returns-qNaN.patch" From a50ee5a4747a99c70469a53fe959f3dc22d3b79a Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda 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(-) diff --git a/newlib/libc/stdlib/gd_qnan.h b/newlib/libc/stdlib/gd_qnan.h index b775f82..3ca337b 100644 --- a/newlib/libc/stdlib/gd_qnan.h +++ b/newlib/libc/stdlib/gd_qnan.h @@ -26,18 +26,18 @@ #elif defined(__IEEE_LITTLE_ENDIAN) #if !defined(__mips) -#define f_QNAN 0xffc00000 +#define f_QNAN 0x7fc00000 #define d_QNAN0 0x0 -#define d_QNAN1 0xfff80000 +#define d_QNAN1 0x7ff80000 #define ld_QNAN0 0x0 #define ld_QNAN1 0xc0000000 -#define ld_QNAN2 0xffff +#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 0xffff +#define ldus_QNAN4 0x7fff #elif defined(__mips_nan2008) #define f_QNAN 0x7fc00000 #define d_QNAN0 0x0 diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index 0cfa9e6..3b9fd26 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -451,6 +451,7 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se, #ifndef No_Hex_NaN } #endif + sign = 0; goto ret; } } -- 2.17.0 ----Next_Part(Tue_Aug_14_13_45_27_2018_543)-- 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(Tue_Aug_14_13_45_27_2018_543)----