public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix strtod ("nan") and strtold ("nan") returns wrong negative NaN Date: Fri, 17 Aug 2018 09:37:00 -0000 [thread overview] Message-ID: <20180817093711.96612.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6c212a8b7873703c4f98c6b68579b234918be83a commit 6c212a8b7873703c4f98c6b68579b234918be83a Author: Masamichi Hosoda <trueroad@trueroad.jp> Date: Thu Aug 16 09:18:50 2018 +0900 Fix strtod ("nan") and strtold ("nan") returns wrong negative NaN The definition of qNaN for x86_64 and i386 was wrong. strto{d|ld} ("nan") returned wrong negative NaN instead of correct positive NaN since it used the wrong definition. On the other hand, strtof ("nan") returns correct positive NaN since it uses nanf ("") instead of the wrong definition. This commit makes strto{d|ld} ("nan") uses {nan|nanl} ("") like strtof ("nan") using. So strto{d|ld} ("nan") returns positive NaN. Diff: --- newlib/libc/stdlib/strtod.c | 5 +---- newlib/libc/stdlib/strtorx.c | 6 +----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index 0cfa9e6..d70d2c2 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -444,10 +444,7 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se, } else { #endif - dword0(rv) = NAN_WORD0; -#ifndef _DOUBLE_IS_32BITS - dword1(rv) = NAN_WORD1; -#endif /*!_DOUBLE_IS_32BITS*/ + dval(rv) = nan (""); #ifndef No_Hex_NaN } #endif diff --git a/newlib/libc/stdlib/strtorx.c b/newlib/libc/stdlib/strtorx.c index aeeb250..f923fdf 100644 --- a/newlib/libc/stdlib/strtorx.c +++ b/newlib/libc/stdlib/strtorx.c @@ -93,11 +93,7 @@ ULtox(__UShort *L, __ULong *bits, Long exp, int k) break; case STRTOG_NaN: - L[0] = ldus_QNAN0; - L[1] = ldus_QNAN1; - L[2] = ldus_QNAN2; - L[3] = ldus_QNAN3; - L[4] = ldus_QNAN4; + *((long double*)L) = nanl (""); } if (k & STRTOG_Neg) L[_0] |= 0x8000;
reply other threads:[~2018-08-17 9:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180817093711.96612.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=newlib-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).