From 7256702e5034b016b5114dd1a6c4c1a689a17816 Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Tue, 14 Aug 2018 23:12:49 +0900 Subject: [PATCH 2/2] Fix strtod ("-nan") returns negative NaN On Linux, glibc's strtod ("-nan") and strtold ("-nan") return positive NaN. But, newlib's strtod ("-nan") returns negative NaN because it inverted the sign with the presence of `-` character. And, newlib's srtold ("-nan") returns negative NaN because it set the sign bit with the presence of `-` character. newlib's strtof ("-nan") returns positive NaN same as Linux glibc's. This commit removes strtod's NaN sign inversion and removes strtold's NaN sign bit setting. So strtod ("-nan") and strtold ("-nan") return positive NaN same as Linux glibc. --- newlib/libc/stdlib/strtod.c | 1 + newlib/libc/stdlib/strtodg.c | 1 + 2 files changed, 2 insertions(+) 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; } } diff --git a/newlib/libc/stdlib/strtodg.c b/newlib/libc/stdlib/strtodg.c index 4ac1f8e..cc2842b 100644 --- a/newlib/libc/stdlib/strtodg.c +++ b/newlib/libc/stdlib/strtodg.c @@ -585,6 +585,7 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp, if (*s == '(') /*)*/ irv = hexnan(&s, fpi, bits); #endif + sign = 0; goto infnanexp; } } -- 2.17.0