]> sourceware.org Git - newlib-cygwin.git/commitdiff
Fix strtod ("nan") and strtold ("nan") returns wrong negative NaN
authorMasamichi Hosoda <trueroad@trueroad.jp>
Thu, 16 Aug 2018 00:18:50 +0000 (09:18 +0900)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 16 Aug 2018 11:17:44 +0000 (13:17 +0200)
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.

newlib/libc/stdlib/strtod.c
newlib/libc/stdlib/strtorx.c

index 0cfa9e6ae78114b06d80b53e8f78d40c6db33c1b..d70d2c25b2ba6ed87d23abae2bb6522c35ba4735 100644 (file)
@@ -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
index aeeb25066dd8948720bc0b58d77f52c06ac0a6cd..f923fdfe1ee1fe228fa89875e43b8109ac6ae055 100644 (file)
@@ -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;
This page took 0.033471 seconds and 5 git commands to generate.