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