|
|
ce426f |
From 8f5e8b01a1da2a207228f2072c934fa5918554b8 Mon Sep 17 00:00:00 2001
|
|
|
ce426f |
From: Joseph Myers <joseph@codesourcery.com>
|
|
|
ce426f |
Date: Fri, 4 Dec 2015 20:36:28 +0000
|
|
|
ce426f |
Subject: [PATCH] Fix nan functions handling of payload strings (bug 16961, bug
|
|
|
ce426f |
16962).
|
|
|
ce426f |
|
|
|
ce426f |
The nan, nanf and nanl functions handle payload strings by doing e.g.:
|
|
|
ce426f |
|
|
|
ce426f |
if (tagp[0] != '\0')
|
|
|
ce426f |
{
|
|
|
ce426f |
char buf[6 + strlen (tagp)];
|
|
|
ce426f |
sprintf (buf, "NAN(%s)", tagp);
|
|
|
ce426f |
return strtod (buf, NULL);
|
|
|
ce426f |
}
|
|
|
ce426f |
|
|
|
ce426f |
This is an unbounded stack allocation based on the length of the
|
|
|
ce426f |
argument. Furthermore, if the argument starts with an n-char-sequence
|
|
|
ce426f |
followed by ')', that n-char-sequence is wrongly treated as
|
|
|
ce426f |
significant for determining the payload of the resulting NaN, when ISO
|
|
|
ce426f |
C says the call should be equivalent to strtod ("NAN", NULL), without
|
|
|
ce426f |
being affected by that initial n-char-sequence. This patch fixes both
|
|
|
ce426f |
those problems by using the __strtod_nan etc. functions recently
|
|
|
ce426f |
factored out of strtod etc. for that purpose, with those functions
|
|
|
ce426f |
being exported from libc at version GLIBC_PRIVATE.
|
|
|
ce426f |
|
|
|
ce426f |
Tested for x86_64, x86, mips64 and powerpc.
|
|
|
ce426f |
|
|
|
ce426f |
[BZ #16961]
|
|
|
ce426f |
[BZ #16962]
|
|
|
ce426f |
* math/s_nan.c (__nan): Use __strtod_nan instead of constructing a
|
|
|
ce426f |
string on the stack for strtod.
|
|
|
ce426f |
* math/s_nanf.c (__nanf): Use __strtof_nan instead of constructing
|
|
|
ce426f |
a string on the stack for strtof.
|
|
|
ce426f |
* math/s_nanl.c (__nanl): Use __strtold_nan instead of
|
|
|
ce426f |
constructing a string on the stack for strtold.
|
|
|
ce426f |
* stdlib/Versions (libc): Add __strtof_nan, __strtod_nan and
|
|
|
ce426f |
__strtold_nan to GLIBC_PRIVATE.
|
|
|
ce426f |
* math/test-nan-overflow.c: New file.
|
|
|
ce426f |
* math/test-nan-payload.c: Likewise.
|
|
|
ce426f |
* math/Makefile (tests): Add test-nan-overflow and
|
|
|
ce426f |
test-nan-payload.
|
|
|
ce426f |
|
|
|
ce426f |
From e02cabecf0d025ec4f4ddee290bdf7aadb873bb3 Mon Sep 17 00:00:00 2001
|
|
|
ce426f |
From: Joseph Myers <joseph@codesourcery.com>
|
|
|
ce426f |
Date: Tue, 24 Nov 2015 22:24:52 +0000
|
|
|
ce426f |
Subject: [PATCH] Refactor strtod parsing of NaN payloads.
|
|
|
ce426f |
|
|
|
ce426f |
The nan* functions handle their string argument by constructing a
|
|
|
ce426f |
NAN(...) string on the stack as a VLA and passing it to strtod
|
|
|
ce426f |
functions.
|
|
|
ce426f |
|
|
|
ce426f |
This approach has problems discussed in bug 16961 and bug 16962: the
|
|
|
ce426f |
stack usage is unbounded, and it gives incorrect results in certain
|
|
|
ce426f |
cases where the argument is not a valid n-char-sequence.
|
|
|
ce426f |
|
|
|
ce426f |
The natural fix for both issues is to refactor the NaN payload parsing
|
|
|
ce426f |
out of strtod into a separate function that the nan* functions can
|
|
|
ce426f |
call directly, so that no temporary string needs constructing on the
|
|
|
ce426f |
stack at all. This patch does that refactoring in preparation for
|
|
|
ce426f |
fixing those bugs (but without actually using the new functions from
|
|
|
ce426f |
nan* - which will also require exporting them from libc at version
|
|
|
ce426f |
GLIBC_PRIVATE). This patch is not intended to change any user-visible
|
|
|
ce426f |
behavior, so no tests are added (fixes for the above bugs will of
|
|
|
ce426f |
course add tests for them).
|
|
|
ce426f |
|
|
|
ce426f |
This patch builds on my recent fixes for strtol and strtod issues in
|
|
|
ce426f |
Turkish locales. Given those fixes, the parsing of NaN payloads is
|
|
|
ce426f |
locale-independent; thus, the new functions do not need to take a
|
|
|
ce426f |
locale_t argument.
|
|
|
ce426f |
|
|
|
ce426f |
Tested for x86_64, x86, mips64 and powerpc.
|
|
|
ce426f |
|
|
|
ce426f |
* stdlib/strtod_nan.c: New file.
|
|
|
ce426f |
* stdlib/strtod_nan_double.h: Likewise.
|
|
|
ce426f |
* stdlib/strtod_nan_float.h: Likewise.
|
|
|
ce426f |
* stdlib/strtod_nan_main.c: Likewise.
|
|
|
ce426f |
* stdlib/strtod_nan_narrow.h: Likewise.
|
|
|
ce426f |
* stdlib/strtod_nan_wide.h: Likewise.
|
|
|
ce426f |
* stdlib/strtof_nan.c: Likewise.
|
|
|
ce426f |
* stdlib/strtold_nan.c: Likewise.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h: Likewise.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h: Likewise.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h: Likewise.
|
|
|
ce426f |
* wcsmbs/wcstod_nan.c: Likewise.
|
|
|
ce426f |
* wcsmbs/wcstof_nan.c: Likewise.
|
|
|
ce426f |
* wcsmbs/wcstold_nan.c: Likewise.
|
|
|
ce426f |
* stdlib/Makefile (routines): Add strtof_nan, strtod_nan and
|
|
|
ce426f |
strtold_nan.
|
|
|
ce426f |
* wcsmbs/Makefile (routines): Add wcstod_nan, wcstold_nan and
|
|
|
ce426f |
wcstof_nan.
|
|
|
ce426f |
* include/stdlib.h (__strtof_nan): Declare and use
|
|
|
ce426f |
libc_hidden_proto.
|
|
|
ce426f |
(__strtod_nan): Likewise.
|
|
|
ce426f |
(__strtold_nan): Likewise.
|
|
|
ce426f |
(__wcstof_nan): Likewise.
|
|
|
ce426f |
(__wcstod_nan): Likewise.
|
|
|
ce426f |
(__wcstold_nan): Likewise.
|
|
|
ce426f |
* include/wchar.h (____wcstoull_l_internal): Declare.
|
|
|
ce426f |
* stdlib/strtod_l.c: Do not include <ieee754.h>.
|
|
|
ce426f |
(____strtoull_l_internal): Remove declaration.
|
|
|
ce426f |
(STRTOF_NAN): Define macro.
|
|
|
ce426f |
(SET_MANTISSA): Remove macro.
|
|
|
ce426f |
(STRTOULL): Likewise.
|
|
|
ce426f |
(____STRTOF_INTERNAL): Use STRTOF_NAN to parse NaN payload.
|
|
|
ce426f |
* stdlib/strtof_l.c (____strtoull_l_internal): Remove declaration.
|
|
|
ce426f |
(STRTOF_NAN): Define macro.
|
|
|
ce426f |
(SET_MANTISSA): Remove macro.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-128/strtold_l.c (STRTOF_NAN): Define macro.
|
|
|
ce426f |
(SET_MANTISSA): Remove macro.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-128ibm/strtold_l.c (STRTOF_NAN): Define
|
|
|
ce426f |
macro.
|
|
|
ce426f |
(SET_MANTISSA): Remove macro.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-64-128/strtold_l.c (STRTOF_NAN): Define
|
|
|
ce426f |
macro.
|
|
|
ce426f |
(SET_MANTISSA): Remove macro.
|
|
|
ce426f |
* sysdeps/ieee754/ldbl-96/strtold_l.c (STRTOF_NAN): Define macro.
|
|
|
ce426f |
(SET_MANTISSA): Remove macro.
|
|
|
ce426f |
* wcsmbs/wcstod_l.c (____wcstoull_l_internal): Remove declaration.
|
|
|
ce426f |
* wcsmbs/wcstof_l.c (____wcstoull_l_internal): Likewise.
|
|
|
ce426f |
* wcsmbs/wcstold_l.c (____wcstoull_l_internal): Likewise.
|
|
|
ce426f |
|
|
|
ce426f |
diff -rupN a/include/stdlib.h b/include/stdlib.h
|
|
|
ce426f |
--- a/include/stdlib.h 2017-03-02 16:34:01.000000000 -0500
|
|
|
ce426f |
+++ b/include/stdlib.h 2017-03-02 16:45:05.457639119 -0500
|
|
|
ce426f |
@@ -193,6 +193,24 @@ libc_hidden_proto (strtoll)
|
|
|
ce426f |
libc_hidden_proto (strtoul)
|
|
|
ce426f |
libc_hidden_proto (strtoull)
|
|
|
ce426f |
|
|
|
ce426f |
+extern float __strtof_nan (const char *, char **, char) internal_function;
|
|
|
ce426f |
+extern double __strtod_nan (const char *, char **, char) internal_function;
|
|
|
ce426f |
+extern long double __strtold_nan (const char *, char **, char)
|
|
|
ce426f |
+ internal_function;
|
|
|
ce426f |
+extern float __wcstof_nan (const wchar_t *, wchar_t **, wchar_t)
|
|
|
ce426f |
+ internal_function;
|
|
|
ce426f |
+extern double __wcstod_nan (const wchar_t *, wchar_t **, wchar_t)
|
|
|
ce426f |
+ internal_function;
|
|
|
ce426f |
+extern long double __wcstold_nan (const wchar_t *, wchar_t **, wchar_t)
|
|
|
ce426f |
+ internal_function;
|
|
|
ce426f |
+
|
|
|
ce426f |
+libc_hidden_proto (__strtof_nan)
|
|
|
ce426f |
+libc_hidden_proto (__strtod_nan)
|
|
|
ce426f |
+libc_hidden_proto (__strtold_nan)
|
|
|
ce426f |
+libc_hidden_proto (__wcstof_nan)
|
|
|
ce426f |
+libc_hidden_proto (__wcstod_nan)
|
|
|
ce426f |
+libc_hidden_proto (__wcstold_nan)
|
|
|
ce426f |
+
|
|
|
ce426f |
extern char *__ecvt (double __value, int __ndigit, int *__restrict __decpt,
|
|
|
ce426f |
int *__restrict __sign);
|
|
|
ce426f |
extern char *__fcvt (double __value, int __ndigit, int *__restrict __decpt,
|
|
|
ce426f |
diff -rupN a/include/wchar.h b/include/wchar.h
|
|
|
ce426f |
--- a/include/wchar.h 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/include/wchar.h 2017-03-02 16:45:05.461639109 -0500
|
|
|
ce426f |
@@ -52,6 +52,9 @@ extern unsigned long long int __wcstoull
|
|
|
ce426f |
__restrict __endptr,
|
|
|
ce426f |
int __base,
|
|
|
ce426f |
int __group) __THROW;
|
|
|
ce426f |
+extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
|
|
|
ce426f |
+ wchar_t **, int, int,
|
|
|
ce426f |
+ __locale_t);
|
|
|
ce426f |
libc_hidden_proto (__wcstof_internal)
|
|
|
ce426f |
libc_hidden_proto (__wcstod_internal)
|
|
|
ce426f |
libc_hidden_proto (__wcstold_internal)
|
|
|
ce426f |
diff -rupN a/math/Makefile b/math/Makefile
|
|
|
ce426f |
--- a/math/Makefile 2017-03-02 16:34:02.000000000 -0500
|
|
|
ce426f |
+++ b/math/Makefile 2017-03-02 16:44:30.659725844 -0500
|
|
|
ce426f |
@@ -88,7 +88,8 @@ long-c-yes = $(calls:=l)
|
|
|
ce426f |
tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \
|
|
|
ce426f |
test-misc test-fpucw tst-definitions test-tgmath test-tgmath-ret \
|
|
|
ce426f |
bug-nextafter bug-nexttoward bug-tgmath1 test-tgmath-int \
|
|
|
ce426f |
- test-tgmath2 test-powl tst-CMPLX tst-CMPLX2
|
|
|
ce426f |
+ test-tgmath2 test-powl tst-CMPLX tst-CMPLX2 \
|
|
|
ce426f |
+ test-nan-overflow test-nan-payload
|
|
|
ce426f |
# We do the `long double' tests only if this data type is available and
|
|
|
ce426f |
# distinct from `double'.
|
|
|
ce426f |
test-longdouble-yes = test-ldouble test-ildoubl
|
|
|
ce426f |
diff -rupN a/math/s_nan.c b/math/s_nan.c
|
|
|
ce426f |
--- a/math/s_nan.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/math/s_nan.c 2017-03-02 16:43:01.680999065 -0500
|
|
|
ce426f |
@@ -28,14 +28,7 @@
|
|
|
ce426f |
double
|
|
|
ce426f |
__nan (const char *tagp)
|
|
|
ce426f |
{
|
|
|
ce426f |
- if (tagp[0] != '\0')
|
|
|
ce426f |
- {
|
|
|
ce426f |
- char buf[6 + strlen (tagp)];
|
|
|
ce426f |
- sprintf (buf, "NAN(%s)", tagp);
|
|
|
ce426f |
- return strtod (buf, NULL);
|
|
|
ce426f |
- }
|
|
|
ce426f |
-
|
|
|
ce426f |
- return NAN;
|
|
|
ce426f |
+ return __strtod_nan (tagp, NULL, 0);
|
|
|
ce426f |
}
|
|
|
ce426f |
weak_alias (__nan, nan)
|
|
|
ce426f |
#ifdef NO_LONG_DOUBLE
|
|
|
ce426f |
diff -rupN a/math/s_nanf.c b/math/s_nanf.c
|
|
|
ce426f |
--- a/math/s_nanf.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/math/s_nanf.c 2017-03-02 16:43:01.683999054 -0500
|
|
|
ce426f |
@@ -28,13 +28,6 @@
|
|
|
ce426f |
float
|
|
|
ce426f |
__nanf (const char *tagp)
|
|
|
ce426f |
{
|
|
|
ce426f |
- if (tagp[0] != '\0')
|
|
|
ce426f |
- {
|
|
|
ce426f |
- char buf[6 + strlen (tagp)];
|
|
|
ce426f |
- sprintf (buf, "NAN(%s)", tagp);
|
|
|
ce426f |
- return strtof (buf, NULL);
|
|
|
ce426f |
- }
|
|
|
ce426f |
-
|
|
|
ce426f |
- return NAN;
|
|
|
ce426f |
+ return __strtof_nan (tagp, NULL, 0);
|
|
|
ce426f |
}
|
|
|
ce426f |
weak_alias (__nanf, nanf)
|
|
|
ce426f |
diff -rupN a/math/s_nanl.c b/math/s_nanl.c
|
|
|
ce426f |
--- a/math/s_nanl.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/math/s_nanl.c 2017-03-02 16:43:01.686999044 -0500
|
|
|
ce426f |
@@ -28,13 +28,6 @@
|
|
|
ce426f |
long double
|
|
|
ce426f |
__nanl (const char *tagp)
|
|
|
ce426f |
{
|
|
|
ce426f |
- if (tagp[0] != '\0')
|
|
|
ce426f |
- {
|
|
|
ce426f |
- char buf[6 + strlen (tagp)];
|
|
|
ce426f |
- sprintf (buf, "NAN(%s)", tagp);
|
|
|
ce426f |
- return strtold (buf, NULL);
|
|
|
ce426f |
- }
|
|
|
ce426f |
-
|
|
|
ce426f |
- return NAN;
|
|
|
ce426f |
+ return __strtold_nan (tagp, NULL, 0);
|
|
|
ce426f |
}
|
|
|
ce426f |
weak_alias (__nanl, nanl)
|
|
|
ce426f |
diff -rupN a/math/test-nan-overflow.c b/math/test-nan-overflow.c
|
|
|
ce426f |
--- a/math/test-nan-overflow.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/math/test-nan-overflow.c 2017-03-02 16:43:01.689999033 -0500
|
|
|
ce426f |
@@ -0,0 +1,66 @@
|
|
|
ce426f |
+/* Test nan functions stack overflow (bug 16962).
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <math.h>
|
|
|
ce426f |
+#include <stdio.h>
|
|
|
ce426f |
+#include <string.h>
|
|
|
ce426f |
+#include <sys/resource.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STACK_LIM 1048576
|
|
|
ce426f |
+#define STRING_SIZE (2 * STACK_LIM)
|
|
|
ce426f |
+
|
|
|
ce426f |
+static int
|
|
|
ce426f |
+do_test (void)
|
|
|
ce426f |
+{
|
|
|
ce426f |
+ int result = 0;
|
|
|
ce426f |
+ struct rlimit lim;
|
|
|
ce426f |
+ getrlimit (RLIMIT_STACK, &lim);
|
|
|
ce426f |
+ lim.rlim_cur = STACK_LIM;
|
|
|
ce426f |
+ setrlimit (RLIMIT_STACK, &lim);
|
|
|
ce426f |
+ char *nanstr = malloc (STRING_SIZE);
|
|
|
ce426f |
+ if (nanstr == NULL)
|
|
|
ce426f |
+ {
|
|
|
ce426f |
+ puts ("malloc failed, cannot test");
|
|
|
ce426f |
+ return 77;
|
|
|
ce426f |
+ }
|
|
|
ce426f |
+ memset (nanstr, '0', STRING_SIZE - 1);
|
|
|
ce426f |
+ nanstr[STRING_SIZE - 1] = 0;
|
|
|
ce426f |
+#define NAN_TEST(TYPE, FUNC) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ char *volatile p = nanstr; \
|
|
|
ce426f |
+ volatile TYPE v = FUNC (p); \
|
|
|
ce426f |
+ if (isnan (v)) \
|
|
|
ce426f |
+ puts ("PASS: " #FUNC); \
|
|
|
ce426f |
+ else \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ puts ("FAIL: " #FUNC); \
|
|
|
ce426f |
+ result = 1; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
+ NAN_TEST (float, nanf);
|
|
|
ce426f |
+ NAN_TEST (double, nan);
|
|
|
ce426f |
+#ifndef NO_LONG_DOUBLE
|
|
|
ce426f |
+ NAN_TEST (long double, nanl);
|
|
|
ce426f |
+#endif
|
|
|
ce426f |
+ return result;
|
|
|
ce426f |
+}
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define TEST_FUNCTION do_test ()
|
|
|
ce426f |
+#include "../test-skeleton.c"
|
|
|
ce426f |
diff -rupN a/math/test-nan-payload.c b/math/test-nan-payload.c
|
|
|
ce426f |
--- a/math/test-nan-payload.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/math/test-nan-payload.c 2017-03-02 16:43:01.693999019 -0500
|
|
|
ce426f |
@@ -0,0 +1,122 @@
|
|
|
ce426f |
+/* Test nan functions payload handling (bug 16961).
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <float.h>
|
|
|
ce426f |
+#include <math.h>
|
|
|
ce426f |
+#include <stdio.h>
|
|
|
ce426f |
+#include <stdlib.h>
|
|
|
ce426f |
+#include <string.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+/* Avoid built-in functions. */
|
|
|
ce426f |
+#define WRAP_NAN(FUNC, STR) \
|
|
|
ce426f |
+ ({ const char *volatile wns = (STR); FUNC (wns); })
|
|
|
ce426f |
+#define WRAP_STRTO(FUNC, STR) \
|
|
|
ce426f |
+ ({ const char *volatile wss = (STR); FUNC (wss, NULL); })
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define CHECK_IS_NAN(TYPE, A) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ if (isnan (A)) \
|
|
|
ce426f |
+ puts ("PASS: " #TYPE " " #A); \
|
|
|
ce426f |
+ else \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ puts ("FAIL: " #TYPE " " #A); \
|
|
|
ce426f |
+ result = 1; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define CHECK_SAME_NAN(TYPE, A, B) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ if (memcmp (&(A), &(B), sizeof (A)) == 0) \
|
|
|
ce426f |
+ puts ("PASS: " #TYPE " " #A " = " #B); \
|
|
|
ce426f |
+ else \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ puts ("FAIL: " #TYPE " " #A " = " #B); \
|
|
|
ce426f |
+ result = 1; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define CHECK_DIFF_NAN(TYPE, A, B) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ if (memcmp (&(A), &(B), sizeof (A)) != 0) \
|
|
|
ce426f |
+ puts ("PASS: " #TYPE " " #A " != " #B); \
|
|
|
ce426f |
+ else \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ puts ("FAIL: " #TYPE " " #A " != " #B); \
|
|
|
ce426f |
+ result = 1; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
+
|
|
|
ce426f |
+/* Cannot test payloads by memcmp for formats where NaNs have padding
|
|
|
ce426f |
+ bits. */
|
|
|
ce426f |
+#define CAN_TEST_EQ(MANT_DIG) ((MANT_DIG) != 64 && (MANT_DIG) != 106)
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define RUN_TESTS(TYPE, SFUNC, FUNC, MANT_DIG) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ TYPE n123 = WRAP_NAN (FUNC, "123"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, n123); \
|
|
|
ce426f |
+ TYPE s123 = WRAP_STRTO (SFUNC, "NAN(123)"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, s123); \
|
|
|
ce426f |
+ TYPE n456 = WRAP_NAN (FUNC, "456"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, n456); \
|
|
|
ce426f |
+ TYPE s456 = WRAP_STRTO (SFUNC, "NAN(456)"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, s456); \
|
|
|
ce426f |
+ TYPE n123x = WRAP_NAN (FUNC, "123)"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, n123x); \
|
|
|
ce426f |
+ TYPE nemp = WRAP_NAN (FUNC, ""); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, nemp); \
|
|
|
ce426f |
+ TYPE semp = WRAP_STRTO (SFUNC, "NAN()"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, semp); \
|
|
|
ce426f |
+ TYPE sx = WRAP_STRTO (SFUNC, "NAN"); \
|
|
|
ce426f |
+ CHECK_IS_NAN (TYPE, sx); \
|
|
|
ce426f |
+ if (CAN_TEST_EQ (MANT_DIG)) \
|
|
|
ce426f |
+ CHECK_SAME_NAN (TYPE, n123, s123); \
|
|
|
ce426f |
+ if (CAN_TEST_EQ (MANT_DIG)) \
|
|
|
ce426f |
+ CHECK_SAME_NAN (TYPE, n456, s456); \
|
|
|
ce426f |
+ if (CAN_TEST_EQ (MANT_DIG)) \
|
|
|
ce426f |
+ CHECK_SAME_NAN (TYPE, nemp, semp); \
|
|
|
ce426f |
+ if (CAN_TEST_EQ (MANT_DIG)) \
|
|
|
ce426f |
+ CHECK_SAME_NAN (TYPE, n123x, sx); \
|
|
|
ce426f |
+ CHECK_DIFF_NAN (TYPE, n123, n456); \
|
|
|
ce426f |
+ CHECK_DIFF_NAN (TYPE, n123, nemp); \
|
|
|
ce426f |
+ CHECK_DIFF_NAN (TYPE, n123, n123x); \
|
|
|
ce426f |
+ CHECK_DIFF_NAN (TYPE, n456, nemp); \
|
|
|
ce426f |
+ CHECK_DIFF_NAN (TYPE, n456, n123x); \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
+
|
|
|
ce426f |
+static int
|
|
|
ce426f |
+do_test (void)
|
|
|
ce426f |
+{
|
|
|
ce426f |
+ int result = 0;
|
|
|
ce426f |
+ RUN_TESTS (float, strtof, nanf, FLT_MANT_DIG);
|
|
|
ce426f |
+ RUN_TESTS (double, strtod, nan, DBL_MANT_DIG);
|
|
|
ce426f |
+#ifndef NO_LONG_DOUBLE
|
|
|
ce426f |
+ RUN_TESTS (long double, strtold, nanl, LDBL_MANT_DIG);
|
|
|
ce426f |
+#endif
|
|
|
ce426f |
+ return result;
|
|
|
ce426f |
+}
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define TEST_FUNCTION do_test ()
|
|
|
ce426f |
+#include "../test-skeleton.c"
|
|
|
ce426f |
diff -rupN a/stdlib/Makefile b/stdlib/Makefile
|
|
|
ce426f |
--- a/stdlib/Makefile 2017-03-02 16:34:02.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/Makefile 2017-03-02 16:45:05.463639105 -0500
|
|
|
ce426f |
@@ -47,6 +47,7 @@ routines := \
|
|
|
ce426f |
strtol_l strtoul_l strtoll_l strtoull_l \
|
|
|
ce426f |
strtof strtod strtold \
|
|
|
ce426f |
strtof_l strtod_l strtold_l \
|
|
|
ce426f |
+ strtof_nan strtod_nan strtold_nan \
|
|
|
ce426f |
system canonicalize \
|
|
|
ce426f |
a64l l64a \
|
|
|
ce426f |
rpmatch strfmon strfmon_l getsubopt xpg_basename fmtmsg \
|
|
|
ce426f |
diff -rupN a/stdlib/Versions b/stdlib/Versions
|
|
|
ce426f |
--- a/stdlib/Versions 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/Versions 2017-03-02 16:44:52.140671064 -0500
|
|
|
ce426f |
@@ -114,5 +114,6 @@ libc {
|
|
|
ce426f |
__abort_msg;
|
|
|
ce426f |
# Used from other libraries
|
|
|
ce426f |
__libc_secure_getenv;
|
|
|
ce426f |
+ __strtof_nan; __strtod_nan; __strtold_nan;
|
|
|
ce426f |
}
|
|
|
ce426f |
}
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_l.c b/stdlib/strtod_l.c
|
|
|
ce426f |
--- a/stdlib/strtod_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_l.c 2017-03-02 16:59:50.224590342 -0500
|
|
|
ce426f |
@@ -20,8 +20,6 @@
|
|
|
ce426f |
#include <xlocale.h>
|
|
|
ce426f |
|
|
|
ce426f |
extern double ____strtod_l_internal (const char *, char **, int, __locale_t);
|
|
|
ce426f |
-extern unsigned long long int ____strtoull_l_internal (const char *, char **,
|
|
|
ce426f |
- int, int, __locale_t);
|
|
|
ce426f |
|
|
|
ce426f |
/* Configuration part. These macros are defined by `strtold.c',
|
|
|
ce426f |
`strtof.c', `wcstod.c', `wcstold.c', and `wcstof.c' to produce the
|
|
|
ce426f |
@@ -33,28 +31,20 @@ extern unsigned long long int ____strtou
|
|
|
ce426f |
# ifdef USE_WIDE_CHAR
|
|
|
ce426f |
# define STRTOF wcstod_l
|
|
|
ce426f |
# define __STRTOF __wcstod_l
|
|
|
ce426f |
+# define STRTOF_NAN __wcstod_nan
|
|
|
ce426f |
# else
|
|
|
ce426f |
# define STRTOF strtod_l
|
|
|
ce426f |
# define __STRTOF __strtod_l
|
|
|
ce426f |
+# define STRTOF_NAN __strtod_nan
|
|
|
ce426f |
# endif
|
|
|
ce426f |
# define MPN2FLOAT __mpn_construct_double
|
|
|
ce426f |
# define FLOAT_HUGE_VAL HUGE_VAL
|
|
|
ce426f |
-# define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
- do { union ieee754_double u; \
|
|
|
ce426f |
- u.d = (flt); \
|
|
|
ce426f |
- if ((mant & 0xfffffffffffffULL) == 0) \
|
|
|
ce426f |
- mant = 0x8000000000000ULL; \
|
|
|
ce426f |
- u.ieee.mantissa0 = ((mant) >> 32) & 0xfffff; \
|
|
|
ce426f |
- u.ieee.mantissa1 = (mant) & 0xffffffff; \
|
|
|
ce426f |
- (flt) = u.d; \
|
|
|
ce426f |
- } while (0)
|
|
|
ce426f |
#endif
|
|
|
ce426f |
/* End of configuration part. */
|
|
|
ce426f |
|
|
|
ce426f |
#include <ctype.h>
|
|
|
ce426f |
#include <errno.h>
|
|
|
ce426f |
#include <float.h>
|
|
|
ce426f |
-#include <ieee754.h>
|
|
|
ce426f |
#include "../locale/localeinfo.h"
|
|
|
ce426f |
#include <locale.h>
|
|
|
ce426f |
#include <math.h>
|
|
|
ce426f |
@@ -105,7 +95,6 @@ extern unsigned long long int ____strtou
|
|
|
ce426f |
# define TOLOWER_C(Ch) __towlower_l ((Ch), _nl_C_locobj_ptr)
|
|
|
ce426f |
# define STRNCASECMP(S1, S2, N) \
|
|
|
ce426f |
__wcsncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr)
|
|
|
ce426f |
-# define STRTOULL(S, E, B) ____wcstoull_l_internal ((S), (E), (B), 0, loc)
|
|
|
ce426f |
#else
|
|
|
ce426f |
# define STRING_TYPE char
|
|
|
ce426f |
# define CHAR_TYPE char
|
|
|
ce426f |
@@ -117,7 +106,6 @@ extern unsigned long long int ____strtou
|
|
|
ce426f |
# define TOLOWER_C(Ch) __tolower_l ((Ch), _nl_C_locobj_ptr)
|
|
|
ce426f |
# define STRNCASECMP(S1, S2, N) \
|
|
|
ce426f |
__strncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr)
|
|
|
ce426f |
-# define STRTOULL(S, E, B) ____strtoull_l_internal ((S), (E), (B), 0, loc)
|
|
|
ce426f |
#endif
|
|
|
ce426f |
|
|
|
ce426f |
|
|
|
ce426f |
@@ -649,33 +637,14 @@ ____STRTOF_INTERNAL (nptr, endptr, group
|
|
|
ce426f |
if (*cp == L_('('))
|
|
|
ce426f |
{
|
|
|
ce426f |
const STRING_TYPE *startp = cp;
|
|
|
ce426f |
- do
|
|
|
ce426f |
- ++cp;
|
|
|
ce426f |
- while ((*cp >= L_('0') && *cp <= L_('9'))
|
|
|
ce426f |
- || ({ CHAR_TYPE lo = TOLOWER (*cp);
|
|
|
ce426f |
- lo >= L_('a') && lo <= L_('z'); })
|
|
|
ce426f |
- || *cp == L_('_'));
|
|
|
ce426f |
-
|
|
|
ce426f |
- if (*cp != L_(')'))
|
|
|
ce426f |
- /* The closing brace is missing. Only match the NAN
|
|
|
ce426f |
- part. */
|
|
|
ce426f |
- cp = startp;
|
|
|
ce426f |
+ STRING_TYPE *endp;
|
|
|
ce426f |
+ retval = STRTOF_NAN (cp + 1, &endp, L_(')'));
|
|
|
ce426f |
+ if (*endp == L_(')'))
|
|
|
ce426f |
+ /* Consume the closing parenthesis. */
|
|
|
ce426f |
+ cp = endp + 1;
|
|
|
ce426f |
else
|
|
|
ce426f |
- {
|
|
|
ce426f |
- /* This is a system-dependent way to specify the
|
|
|
ce426f |
- bitmask used for the NaN. We expect it to be
|
|
|
ce426f |
- a number which is put in the mantissa of the
|
|
|
ce426f |
- number. */
|
|
|
ce426f |
- STRING_TYPE *endp;
|
|
|
ce426f |
- unsigned long long int mant;
|
|
|
ce426f |
-
|
|
|
ce426f |
- mant = STRTOULL (startp + 1, &endp, 0);
|
|
|
ce426f |
- if (endp == cp)
|
|
|
ce426f |
- SET_MANTISSA (retval, mant);
|
|
|
ce426f |
-
|
|
|
ce426f |
- /* Consume the closing brace. */
|
|
|
ce426f |
- ++cp;
|
|
|
ce426f |
- }
|
|
|
ce426f |
+ /* Only match the NAN part. */
|
|
|
ce426f |
+ cp = startp;
|
|
|
ce426f |
}
|
|
|
ce426f |
|
|
|
ce426f |
if (endptr != NULL)
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_nan.c b/stdlib/strtod_nan.c
|
|
|
ce426f |
--- a/stdlib/strtod_nan.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_nan.c 2017-03-02 16:45:05.473639081 -0500
|
|
|
ce426f |
@@ -0,0 +1,24 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Narrow
|
|
|
ce426f |
+ strings, double.
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <strtod_nan_narrow.h>
|
|
|
ce426f |
+#include <strtod_nan_double.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STRTOD_NAN __strtod_nan
|
|
|
ce426f |
+#include <strtod_nan_main.c>
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_nan_double.h b/stdlib/strtod_nan_double.h
|
|
|
ce426f |
--- a/stdlib/strtod_nan_double.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_nan_double.h 2017-03-02 16:45:05.477639072 -0500
|
|
|
ce426f |
@@ -0,0 +1,30 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. For double.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define FLOAT double
|
|
|
ce426f |
+#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ union ieee754_double u; \
|
|
|
ce426f |
+ u.d = (flt); \
|
|
|
ce426f |
+ u.ieee_nan.mantissa0 = (mant) >> 32; \
|
|
|
ce426f |
+ u.ieee_nan.mantissa1 = (mant); \
|
|
|
ce426f |
+ if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \
|
|
|
ce426f |
+ (flt) = u.d; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_nan_float.h b/stdlib/strtod_nan_float.h
|
|
|
ce426f |
--- a/stdlib/strtod_nan_float.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_nan_float.h 2017-03-02 16:45:05.480639065 -0500
|
|
|
ce426f |
@@ -0,0 +1,29 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. For float.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define FLOAT float
|
|
|
ce426f |
+#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ union ieee754_float u; \
|
|
|
ce426f |
+ u.f = (flt); \
|
|
|
ce426f |
+ u.ieee_nan.mantissa = (mant); \
|
|
|
ce426f |
+ if (u.ieee.mantissa != 0) \
|
|
|
ce426f |
+ (flt) = u.f; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_nan_main.c b/stdlib/strtod_nan_main.c
|
|
|
ce426f |
--- a/stdlib/strtod_nan_main.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_nan_main.c 2017-03-02 16:45:05.483639058 -0500
|
|
|
ce426f |
@@ -0,0 +1,63 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <ieee754.h>
|
|
|
ce426f |
+#include <locale.h>
|
|
|
ce426f |
+#include <math.h>
|
|
|
ce426f |
+#include <stdlib.h>
|
|
|
ce426f |
+#include <wchar.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+
|
|
|
ce426f |
+/* If STR starts with an optional n-char-sequence as defined by ISO C
|
|
|
ce426f |
+ (a sequence of ASCII letters, digits and underscores), followed by
|
|
|
ce426f |
+ ENDC, return a NaN whose payload is set based on STR. Otherwise,
|
|
|
ce426f |
+ return a default NAN. If ENDPTR is not NULL, set *ENDPTR to point
|
|
|
ce426f |
+ to the character after the initial n-char-sequence. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+internal_function
|
|
|
ce426f |
+FLOAT
|
|
|
ce426f |
+STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc)
|
|
|
ce426f |
+{
|
|
|
ce426f |
+ const STRING_TYPE *cp = str;
|
|
|
ce426f |
+
|
|
|
ce426f |
+ while ((*cp >= L_('0') && *cp <= L_('9'))
|
|
|
ce426f |
+ || (*cp >= L_('A') && *cp <= L_('Z'))
|
|
|
ce426f |
+ || (*cp >= L_('a') && *cp <= L_('z'))
|
|
|
ce426f |
+ || *cp == L_('_'))
|
|
|
ce426f |
+ ++cp;
|
|
|
ce426f |
+
|
|
|
ce426f |
+ FLOAT retval = NAN;
|
|
|
ce426f |
+ if (*cp != endc)
|
|
|
ce426f |
+ goto out;
|
|
|
ce426f |
+
|
|
|
ce426f |
+ /* This is a system-dependent way to specify the bitmask used for
|
|
|
ce426f |
+ the NaN. We expect it to be a number which is put in the
|
|
|
ce426f |
+ mantissa of the number. */
|
|
|
ce426f |
+ STRING_TYPE *endp;
|
|
|
ce426f |
+ unsigned long long int mant;
|
|
|
ce426f |
+
|
|
|
ce426f |
+ mant = STRTOULL (str, &endp, 0);
|
|
|
ce426f |
+ if (endp == cp)
|
|
|
ce426f |
+ SET_MANTISSA (retval, mant);
|
|
|
ce426f |
+
|
|
|
ce426f |
+ out:
|
|
|
ce426f |
+ if (endptr != NULL)
|
|
|
ce426f |
+ *endptr = (STRING_TYPE *) cp;
|
|
|
ce426f |
+ return retval;
|
|
|
ce426f |
+}
|
|
|
ce426f |
+libc_hidden_def (STRTOD_NAN)
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_nan_narrow.h b/stdlib/strtod_nan_narrow.h
|
|
|
ce426f |
--- a/stdlib/strtod_nan_narrow.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_nan_narrow.h 2017-03-02 16:45:05.486639051 -0500
|
|
|
ce426f |
@@ -0,0 +1,22 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Narrow strings.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STRING_TYPE char
|
|
|
ce426f |
+#define L_(Ch) Ch
|
|
|
ce426f |
+#define STRTOULL(S, E, B) ____strtoull_l_internal ((S), (E), (B), 0, \
|
|
|
ce426f |
+ _nl_C_locobj_ptr)
|
|
|
ce426f |
diff -rupN a/stdlib/strtod_nan_wide.h b/stdlib/strtod_nan_wide.h
|
|
|
ce426f |
--- a/stdlib/strtod_nan_wide.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtod_nan_wide.h 2017-03-02 16:45:05.489639044 -0500
|
|
|
ce426f |
@@ -0,0 +1,22 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Wide strings.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STRING_TYPE wchar_t
|
|
|
ce426f |
+#define L_(Ch) L##Ch
|
|
|
ce426f |
+#define STRTOULL(S, E, B) ____wcstoull_l_internal ((S), (E), (B), 0, \
|
|
|
ce426f |
+ _nl_C_locobj_ptr)
|
|
|
ce426f |
diff -rupN a/stdlib/strtof_l.c b/stdlib/strtof_l.c
|
|
|
ce426f |
--- a/stdlib/strtof_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtof_l.c 2017-03-02 17:06:34.349227993 -0500
|
|
|
ce426f |
@@ -20,27 +20,19 @@
|
|
|
ce426f |
#include <xlocale.h>
|
|
|
ce426f |
|
|
|
ce426f |
extern float ____strtof_l_internal (const char *, char **, int, __locale_t);
|
|
|
ce426f |
-extern unsigned long long int ____strtoull_l_internal (const char *, char **,
|
|
|
ce426f |
- int, int, __locale_t);
|
|
|
ce426f |
|
|
|
ce426f |
#define FLOAT float
|
|
|
ce426f |
#define FLT FLT
|
|
|
ce426f |
#ifdef USE_WIDE_CHAR
|
|
|
ce426f |
# define STRTOF wcstof_l
|
|
|
ce426f |
# define __STRTOF __wcstof_l
|
|
|
ce426f |
+# define STRTOF_NAN __wcstof_nan
|
|
|
ce426f |
#else
|
|
|
ce426f |
# define STRTOF strtof_l
|
|
|
ce426f |
# define __STRTOF __strtof_l
|
|
|
ce426f |
+# define STRTOF_NAN __strtof_nan
|
|
|
ce426f |
#endif
|
|
|
ce426f |
#define MPN2FLOAT __mpn_construct_float
|
|
|
ce426f |
#define FLOAT_HUGE_VAL HUGE_VALF
|
|
|
ce426f |
-#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
- do { union ieee754_float u; \
|
|
|
ce426f |
- u.f = (flt); \
|
|
|
ce426f |
- if ((mant & 0x7fffff) == 0) \
|
|
|
ce426f |
- mant = 0x400000; \
|
|
|
ce426f |
- u.ieee.mantissa = (mant) & 0x7fffff; \
|
|
|
ce426f |
- (flt) = u.f; \
|
|
|
ce426f |
- } while (0)
|
|
|
ce426f |
|
|
|
ce426f |
#include "strtod_l.c"
|
|
|
ce426f |
diff -rupN a/stdlib/strtof_nan.c b/stdlib/strtof_nan.c
|
|
|
ce426f |
--- a/stdlib/strtof_nan.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtof_nan.c 2017-03-02 16:45:05.498639023 -0500
|
|
|
ce426f |
@@ -0,0 +1,24 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Narrow
|
|
|
ce426f |
+ strings, float.
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <strtod_nan_narrow.h>
|
|
|
ce426f |
+#include <strtod_nan_float.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STRTOD_NAN __strtof_nan
|
|
|
ce426f |
+#include <strtod_nan_main.c>
|
|
|
ce426f |
diff -rupN a/stdlib/strtold_nan.c b/stdlib/strtold_nan.c
|
|
|
ce426f |
--- a/stdlib/strtold_nan.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/stdlib/strtold_nan.c 2017-03-02 16:45:05.501639016 -0500
|
|
|
ce426f |
@@ -0,0 +1,30 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Narrow
|
|
|
ce426f |
+ strings, long double.
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <math.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+/* This function is unused if long double and double have the same
|
|
|
ce426f |
+ representation. */
|
|
|
ce426f |
+#ifndef __NO_LONG_DOUBLE_MATH
|
|
|
ce426f |
+# include <strtod_nan_narrow.h>
|
|
|
ce426f |
+# include <strtod_nan_ldouble.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+# define STRTOD_NAN __strtold_nan
|
|
|
ce426f |
+# include <strtod_nan_main.c>
|
|
|
ce426f |
+#endif
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h b/sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h 2017-03-02 16:45:05.502639014 -0500
|
|
|
ce426f |
@@ -0,0 +1,33 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. For ldbl-128.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define FLOAT long double
|
|
|
ce426f |
+#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ union ieee854_long_double u; \
|
|
|
ce426f |
+ u.d = (flt); \
|
|
|
ce426f |
+ u.ieee_nan.mantissa0 = 0; \
|
|
|
ce426f |
+ u.ieee_nan.mantissa1 = 0; \
|
|
|
ce426f |
+ u.ieee_nan.mantissa2 = (mant) >> 32; \
|
|
|
ce426f |
+ u.ieee_nan.mantissa3 = (mant); \
|
|
|
ce426f |
+ if ((u.ieee.mantissa0 | u.ieee.mantissa1 \
|
|
|
ce426f |
+ | u.ieee.mantissa2 | u.ieee.mantissa3) != 0) \
|
|
|
ce426f |
+ (flt) = u.d; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-128/strtold_l.c b/sysdeps/ieee754/ldbl-128/strtold_l.c
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-128/strtold_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-128/strtold_l.c 2017-03-02 17:07:43.540018882 -0500
|
|
|
ce426f |
@@ -25,20 +25,13 @@
|
|
|
ce426f |
#ifdef USE_WIDE_CHAR
|
|
|
ce426f |
# define STRTOF wcstold_l
|
|
|
ce426f |
# define __STRTOF __wcstold_l
|
|
|
ce426f |
+# define STRTOF_NAN __wcstold_nan
|
|
|
ce426f |
#else
|
|
|
ce426f |
# define STRTOF strtold_l
|
|
|
ce426f |
# define __STRTOF __strtold_l
|
|
|
ce426f |
+# define STRTOF_NAN __strtold_nan
|
|
|
ce426f |
#endif
|
|
|
ce426f |
#define MPN2FLOAT __mpn_construct_long_double
|
|
|
ce426f |
#define FLOAT_HUGE_VAL HUGE_VALL
|
|
|
ce426f |
-#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
- do { union ieee854_long_double u; \
|
|
|
ce426f |
- u.d = (flt); \
|
|
|
ce426f |
- u.ieee.mantissa0 = 0x8000; \
|
|
|
ce426f |
- u.ieee.mantissa1 = 0; \
|
|
|
ce426f |
- u.ieee.mantissa2 = ((mant) >> 32); \
|
|
|
ce426f |
- u.ieee.mantissa3 = (mant) & 0xffffffff; \
|
|
|
ce426f |
- (flt) = u.d; \
|
|
|
ce426f |
- } while (0)
|
|
|
ce426f |
|
|
|
ce426f |
#include <strtod_l.c>
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h b/sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h 2017-03-02 16:45:05.505639007 -0500
|
|
|
ce426f |
@@ -0,0 +1,30 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. For ldbl-128ibm.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define FLOAT long double
|
|
|
ce426f |
+#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ union ibm_extended_long_double u; \
|
|
|
ce426f |
+ u.ld = (flt); \
|
|
|
ce426f |
+ u.d[0].ieee_nan.mantissa0 = (mant) >> 32; \
|
|
|
ce426f |
+ u.d[0].ieee_nan.mantissa1 = (mant); \
|
|
|
ce426f |
+ if ((u.d[0].ieee.mantissa0 | u.d[0].ieee.mantissa1) != 0) \
|
|
|
ce426f |
+ (flt) = u.ld; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-128ibm/strtold_l.c b/sysdeps/ieee754/ldbl-128ibm/strtold_l.c
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-128ibm/strtold_l.c 2017-03-02 16:33:54.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-128ibm/strtold_l.c 2017-03-02 17:10:22.516584043 -0500
|
|
|
ce426f |
@@ -30,25 +30,19 @@ extern long double ____new_wcstold_l (co
|
|
|
ce426f |
# define STRTOF __new_wcstold_l
|
|
|
ce426f |
# define __STRTOF ____new_wcstold_l
|
|
|
ce426f |
# define ____STRTOF_INTERNAL ____wcstold_l_internal
|
|
|
ce426f |
+# define STRTOF_NAN __wcstold_nan
|
|
|
ce426f |
#else
|
|
|
ce426f |
extern long double ____new_strtold_l (const char *, char **, __locale_t);
|
|
|
ce426f |
# define STRTOF __new_strtold_l
|
|
|
ce426f |
# define __STRTOF ____new_strtold_l
|
|
|
ce426f |
# define ____STRTOF_INTERNAL ____strtold_l_internal
|
|
|
ce426f |
+# define STRTOF_NAN __strtold_nan
|
|
|
ce426f |
#endif
|
|
|
ce426f |
extern __typeof (__STRTOF) STRTOF;
|
|
|
ce426f |
libc_hidden_proto (__STRTOF)
|
|
|
ce426f |
libc_hidden_proto (STRTOF)
|
|
|
ce426f |
#define MPN2FLOAT __mpn_construct_long_double
|
|
|
ce426f |
#define FLOAT_HUGE_VAL HUGE_VALL
|
|
|
ce426f |
-# define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
- do { union ibm_extended_long_double u; \
|
|
|
ce426f |
- u.ld = (flt); \
|
|
|
ce426f |
- u.d[0].ieee_nan.mantissa0 = (mant) >> 32; \
|
|
|
ce426f |
- u.d[0].ieee_nan.mantissa1 = (mant); \
|
|
|
ce426f |
- if ((u.d[0].ieee.mantissa0 | u.d[0].ieee.mantissa1) != 0) \
|
|
|
ce426f |
- (flt) = u.ld; \
|
|
|
ce426f |
- } while (0)
|
|
|
ce426f |
|
|
|
ce426f |
#include <strtod_l.c>
|
|
|
ce426f |
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-64-128/strtold_l.c b/sysdeps/ieee754/ldbl-64-128/strtold_l.c
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-64-128/strtold_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-64-128/strtold_l.c 2017-03-02 17:11:06.062475088 -0500
|
|
|
ce426f |
@@ -30,26 +30,19 @@ extern long double ____new_wcstold_l (co
|
|
|
ce426f |
# define STRTOF __new_wcstold_l
|
|
|
ce426f |
# define __STRTOF ____new_wcstold_l
|
|
|
ce426f |
# define ____STRTOF_INTERNAL ____wcstold_l_internal
|
|
|
ce426f |
+# define STRTOF_NAN __wcstold_nan
|
|
|
ce426f |
#else
|
|
|
ce426f |
extern long double ____new_strtold_l (const char *, char **, __locale_t);
|
|
|
ce426f |
# define STRTOF __new_strtold_l
|
|
|
ce426f |
# define __STRTOF ____new_strtold_l
|
|
|
ce426f |
# define ____STRTOF_INTERNAL ____strtold_l_internal
|
|
|
ce426f |
+# define STRTOF_NAN __strtold_nan
|
|
|
ce426f |
#endif
|
|
|
ce426f |
extern __typeof (__STRTOF) STRTOF;
|
|
|
ce426f |
libc_hidden_proto (__STRTOF)
|
|
|
ce426f |
libc_hidden_proto (STRTOF)
|
|
|
ce426f |
#define MPN2FLOAT __mpn_construct_long_double
|
|
|
ce426f |
#define FLOAT_HUGE_VAL HUGE_VALL
|
|
|
ce426f |
-#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
- do { union ieee854_long_double u; \
|
|
|
ce426f |
- u.d = (flt); \
|
|
|
ce426f |
- u.ieee.mantissa0 = 0x8000; \
|
|
|
ce426f |
- u.ieee.mantissa1 = 0; \
|
|
|
ce426f |
- u.ieee.mantissa2 = ((mant) >> 32); \
|
|
|
ce426f |
- u.ieee.mantissa3 = (mant) & 0xffffffff; \
|
|
|
ce426f |
- (flt) = u.d; \
|
|
|
ce426f |
- } while (0)
|
|
|
ce426f |
|
|
|
ce426f |
#include <strtod_l.c>
|
|
|
ce426f |
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h b/sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h 2017-03-02 16:45:05.521638969 -0500
|
|
|
ce426f |
@@ -0,0 +1,30 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. For ldbl-96.
|
|
|
ce426f |
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define FLOAT long double
|
|
|
ce426f |
+#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
+ do \
|
|
|
ce426f |
+ { \
|
|
|
ce426f |
+ union ieee854_long_double u; \
|
|
|
ce426f |
+ u.d = (flt); \
|
|
|
ce426f |
+ u.ieee_nan.mantissa0 = (mant) >> 32; \
|
|
|
ce426f |
+ u.ieee_nan.mantissa1 = (mant); \
|
|
|
ce426f |
+ if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \
|
|
|
ce426f |
+ (flt) = u.d; \
|
|
|
ce426f |
+ } \
|
|
|
ce426f |
+ while (0)
|
|
|
ce426f |
diff -rupN a/sysdeps/ieee754/ldbl-96/strtold_l.c b/sysdeps/ieee754/ldbl-96/strtold_l.c
|
|
|
ce426f |
--- a/sysdeps/ieee754/ldbl-96/strtold_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/sysdeps/ieee754/ldbl-96/strtold_l.c 2017-03-02 17:11:52.927362322 -0500
|
|
|
ce426f |
@@ -25,20 +25,13 @@
|
|
|
ce426f |
#ifdef USE_WIDE_CHAR
|
|
|
ce426f |
# define STRTOF wcstold_l
|
|
|
ce426f |
# define __STRTOF __wcstold_l
|
|
|
ce426f |
+# define STRTOF_NAN __wcstold_nan
|
|
|
ce426f |
#else
|
|
|
ce426f |
# define STRTOF strtold_l
|
|
|
ce426f |
# define __STRTOF __strtold_l
|
|
|
ce426f |
+# define STRTOF_NAN __strtold_nan
|
|
|
ce426f |
#endif
|
|
|
ce426f |
#define MPN2FLOAT __mpn_construct_long_double
|
|
|
ce426f |
#define FLOAT_HUGE_VAL HUGE_VALL
|
|
|
ce426f |
-#define SET_MANTISSA(flt, mant) \
|
|
|
ce426f |
- do { union ieee854_long_double u; \
|
|
|
ce426f |
- u.d = (flt); \
|
|
|
ce426f |
- if ((mant & 0x7fffffffffffffffULL) == 0) \
|
|
|
ce426f |
- mant = 0x4000000000000000ULL; \
|
|
|
ce426f |
- u.ieee.mantissa0 = (((mant) >> 32) & 0x7fffffff) | 0x80000000; \
|
|
|
ce426f |
- u.ieee.mantissa1 = (mant) & 0xffffffff; \
|
|
|
ce426f |
- (flt) = u.d; \
|
|
|
ce426f |
- } while (0)
|
|
|
ce426f |
|
|
|
ce426f |
#include <stdlib/strtod_l.c>
|
|
|
ce426f |
diff -rupN a/wcsmbs/Makefile b/wcsmbs/Makefile
|
|
|
ce426f |
--- a/wcsmbs/Makefile 2017-03-02 16:33:59.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/Makefile 2017-03-02 16:45:05.529638950 -0500
|
|
|
ce426f |
@@ -32,6 +32,7 @@ routines := wcscat wcschr wcscmp wcscpy
|
|
|
ce426f |
wcstol wcstoul wcstoll wcstoull wcstod wcstold wcstof \
|
|
|
ce426f |
wcstol_l wcstoul_l wcstoll_l wcstoull_l \
|
|
|
ce426f |
wcstod_l wcstold_l wcstof_l \
|
|
|
ce426f |
+ wcstod_nan wcstold_nan wcstof_nan \
|
|
|
ce426f |
wcscoll wcsxfrm \
|
|
|
ce426f |
wcwidth wcswidth \
|
|
|
ce426f |
wcscoll_l wcsxfrm_l \
|
|
|
ce426f |
diff -rupN a/wcsmbs/wcstod_l.c b/wcsmbs/wcstod_l.c
|
|
|
ce426f |
--- a/wcsmbs/wcstod_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/wcstod_l.c 2017-03-02 16:45:05.532638943 -0500
|
|
|
ce426f |
@@ -23,9 +23,6 @@
|
|
|
ce426f |
|
|
|
ce426f |
extern double ____wcstod_l_internal (const wchar_t *, wchar_t **, int,
|
|
|
ce426f |
__locale_t);
|
|
|
ce426f |
-extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
|
|
|
ce426f |
- wchar_t **, int, int,
|
|
|
ce426f |
- __locale_t);
|
|
|
ce426f |
|
|
|
ce426f |
#define USE_WIDE_CHAR 1
|
|
|
ce426f |
|
|
|
ce426f |
diff -rupN a/wcsmbs/wcstod_nan.c b/wcsmbs/wcstod_nan.c
|
|
|
ce426f |
--- a/wcsmbs/wcstod_nan.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/wcstod_nan.c 2017-03-02 16:45:05.535638936 -0500
|
|
|
ce426f |
@@ -0,0 +1,23 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Wide strings, double.
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include "../stdlib/strtod_nan_wide.h"
|
|
|
ce426f |
+#include "../stdlib/strtod_nan_double.h"
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STRTOD_NAN __wcstod_nan
|
|
|
ce426f |
+#include "../stdlib/strtod_nan_main.c"
|
|
|
ce426f |
diff -rupN a/wcsmbs/wcstof_l.c b/wcsmbs/wcstof_l.c
|
|
|
ce426f |
--- a/wcsmbs/wcstof_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/wcstof_l.c 2017-03-02 16:45:05.538638929 -0500
|
|
|
ce426f |
@@ -25,8 +25,5 @@
|
|
|
ce426f |
|
|
|
ce426f |
extern float ____wcstof_l_internal (const wchar_t *, wchar_t **, int,
|
|
|
ce426f |
__locale_t);
|
|
|
ce426f |
-extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
|
|
|
ce426f |
- wchar_t **, int, int,
|
|
|
ce426f |
- __locale_t);
|
|
|
ce426f |
|
|
|
ce426f |
#include <stdlib/strtof_l.c>
|
|
|
ce426f |
diff -rupN a/wcsmbs/wcstof_nan.c b/wcsmbs/wcstof_nan.c
|
|
|
ce426f |
--- a/wcsmbs/wcstof_nan.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/wcstof_nan.c 2017-03-02 16:45:05.541638922 -0500
|
|
|
ce426f |
@@ -0,0 +1,23 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Wide strings, float.
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include "../stdlib/strtod_nan_wide.h"
|
|
|
ce426f |
+#include "../stdlib/strtod_nan_float.h"
|
|
|
ce426f |
+
|
|
|
ce426f |
+#define STRTOD_NAN __wcstof_nan
|
|
|
ce426f |
+#include "../stdlib/strtod_nan_main.c"
|
|
|
ce426f |
diff -rupN a/wcsmbs/wcstold_l.c b/wcsmbs/wcstold_l.c
|
|
|
ce426f |
--- a/wcsmbs/wcstold_l.c 2012-12-24 22:02:13.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/wcstold_l.c 2017-03-02 16:45:05.544638915 -0500
|
|
|
ce426f |
@@ -24,8 +24,5 @@
|
|
|
ce426f |
|
|
|
ce426f |
extern long double ____wcstold_l_internal (const wchar_t *, wchar_t **, int,
|
|
|
ce426f |
__locale_t);
|
|
|
ce426f |
-extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
|
|
|
ce426f |
- wchar_t **, int, int,
|
|
|
ce426f |
- __locale_t);
|
|
|
ce426f |
|
|
|
ce426f |
#include <strtold_l.c>
|
|
|
ce426f |
diff -rupN a/wcsmbs/wcstold_nan.c b/wcsmbs/wcstold_nan.c
|
|
|
ce426f |
--- a/wcsmbs/wcstold_nan.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
ce426f |
+++ b/wcsmbs/wcstold_nan.c 2017-03-02 16:45:05.547638908 -0500
|
|
|
ce426f |
@@ -0,0 +1,30 @@
|
|
|
ce426f |
+/* Convert string for NaN payload to corresponding NaN. Wide strings,
|
|
|
ce426f |
+ long double.
|
|
|
ce426f |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
ce426f |
+ This file is part of the GNU C Library.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
ce426f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
ce426f |
+ License as published by the Free Software Foundation; either
|
|
|
ce426f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
ce426f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ce426f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
ce426f |
+ Lesser General Public License for more details.
|
|
|
ce426f |
+
|
|
|
ce426f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
ce426f |
+ License along with the GNU C Library; if not, see
|
|
|
ce426f |
+ <http://www.gnu.org/licenses/>. */
|
|
|
ce426f |
+
|
|
|
ce426f |
+#include <math.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+/* This function is unused if long double and double have the same
|
|
|
ce426f |
+ representation. */
|
|
|
ce426f |
+#ifndef __NO_LONG_DOUBLE_MATH
|
|
|
ce426f |
+# include "../stdlib/strtod_nan_wide.h"
|
|
|
ce426f |
+# include <strtod_nan_ldouble.h>
|
|
|
ce426f |
+
|
|
|
ce426f |
+# define STRTOD_NAN __wcstold_nan
|
|
|
ce426f |
+# include "../stdlib/strtod_nan_main.c"
|
|
|
ce426f |
+#endif
|