diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/Makefile | 1 | ||||
-rw-r--r-- | stdlib/strtod_l.c | 48 | ||||
-rw-r--r-- | stdlib/strtod_nan.c | 24 | ||||
-rw-r--r-- | stdlib/strtod_nan_double.h | 30 | ||||
-rw-r--r-- | stdlib/strtod_nan_float.h | 29 | ||||
-rw-r--r-- | stdlib/strtod_nan_main.c | 63 | ||||
-rw-r--r-- | stdlib/strtod_nan_narrow.h | 22 | ||||
-rw-r--r-- | stdlib/strtod_nan_wide.h | 22 | ||||
-rw-r--r-- | stdlib/strtof_l.c | 11 | ||||
-rw-r--r-- | stdlib/strtof_nan.c | 24 | ||||
-rw-r--r-- | stdlib/strtold_nan.c | 30 |
11 files changed, 256 insertions, 48 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile index 10d9406813..d7ae165fc7 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -50,6 +50,7 @@ routines := \ strtol_l strtoul_l strtoll_l strtoull_l \ strtof strtod strtold \ strtof_l strtod_l strtold_l \ + strtof_nan strtod_nan strtold_nan \ system canonicalize \ a64l l64a \ rpmatch strfmon strfmon_l getsubopt xpg_basename fmtmsg \ diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c index 7307d98b24..21692914fd 100644 --- a/stdlib/strtod_l.c +++ b/stdlib/strtod_l.c @@ -20,8 +20,6 @@ #include <xlocale.h> extern double ____strtod_l_internal (const char *, char **, int, __locale_t); -extern unsigned long long int ____strtoull_l_internal (const char *, char **, - int, int, __locale_t); /* Configuration part. These macros are defined by `strtold.c', `strtof.c', `wcstod.c', `wcstold.c', and `wcstof.c' to produce the @@ -33,27 +31,20 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **, # ifdef USE_WIDE_CHAR # define STRTOF wcstod_l # define __STRTOF __wcstod_l +# define STRTOF_NAN __wcstod_nan # else # define STRTOF strtod_l # define __STRTOF __strtod_l +# define STRTOF_NAN __strtod_nan # endif # define MPN2FLOAT __mpn_construct_double # define FLOAT_HUGE_VAL HUGE_VAL -# define SET_MANTISSA(flt, mant) \ - do { union ieee754_double u; \ - u.d = (flt); \ - u.ieee_nan.mantissa0 = (mant) >> 32; \ - u.ieee_nan.mantissa1 = (mant); \ - if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \ - (flt) = u.d; \ - } while (0) #endif /* End of configuration part. */ #include <ctype.h> #include <errno.h> #include <float.h> -#include <ieee754.h> #include "../locale/localeinfo.h" #include <locale.h> #include <math.h> @@ -105,7 +96,6 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **, # define TOLOWER_C(Ch) __towlower_l ((Ch), _nl_C_locobj_ptr) # define STRNCASECMP(S1, S2, N) \ __wcsncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr) -# define STRTOULL(S, E, B) ____wcstoull_l_internal ((S), (E), (B), 0, loc) #else # define STRING_TYPE char # define CHAR_TYPE char @@ -117,7 +107,6 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **, # define TOLOWER_C(Ch) __tolower_l ((Ch), _nl_C_locobj_ptr) # define STRNCASECMP(S1, S2, N) \ __strncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr) -# define STRTOULL(S, E, B) ____strtoull_l_internal ((S), (E), (B), 0, loc) #endif @@ -649,33 +638,14 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group, if (*cp == L_('(')) { const STRING_TYPE *startp = cp; - do - ++cp; - while ((*cp >= L_('0') && *cp <= L_('9')) - || (*cp >= L_('A') && *cp <= L_('Z')) - || (*cp >= L_('a') && *cp <= L_('z')) - || *cp == L_('_')); - - if (*cp != L_(')')) - /* The closing brace is missing. Only match the NAN - part. */ - cp = startp; + STRING_TYPE *endp; + retval = STRTOF_NAN (cp + 1, &endp, L_(')')); + if (*endp == L_(')')) + /* Consume the closing parenthesis. */ + cp = endp + 1; else - { - /* This is a system-dependent way to specify the - bitmask used for the NaN. We expect it to be - a number which is put in the mantissa of the - number. */ - STRING_TYPE *endp; - unsigned long long int mant; - - mant = STRTOULL (startp + 1, &endp, 0); - if (endp == cp) - SET_MANTISSA (retval, mant); - - /* Consume the closing brace. */ - ++cp; - } + /* Only match the NAN part. */ + cp = startp; } if (endptr != NULL) diff --git a/stdlib/strtod_nan.c b/stdlib/strtod_nan.c new file mode 100644 index 0000000000..2a0a89fc73 --- /dev/null +++ b/stdlib/strtod_nan.c @@ -0,0 +1,24 @@ +/* Convert string for NaN payload to corresponding NaN. Narrow + strings, double. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <strtod_nan_narrow.h> +#include <strtod_nan_double.h> + +#define STRTOD_NAN __strtod_nan +#include <strtod_nan_main.c> diff --git a/stdlib/strtod_nan_double.h b/stdlib/strtod_nan_double.h new file mode 100644 index 0000000000..f5bdb03e90 --- /dev/null +++ b/stdlib/strtod_nan_double.h @@ -0,0 +1,30 @@ +/* Convert string for NaN payload to corresponding NaN. For double. + Copyright (C) 1997-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#define FLOAT double +#define SET_MANTISSA(flt, mant) \ + do \ + { \ + union ieee754_double u; \ + u.d = (flt); \ + u.ieee_nan.mantissa0 = (mant) >> 32; \ + u.ieee_nan.mantissa1 = (mant); \ + if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \ + (flt) = u.d; \ + } \ + while (0) diff --git a/stdlib/strtod_nan_float.h b/stdlib/strtod_nan_float.h new file mode 100644 index 0000000000..4c52de8bed --- /dev/null +++ b/stdlib/strtod_nan_float.h @@ -0,0 +1,29 @@ +/* Convert string for NaN payload to corresponding NaN. For float. + Copyright (C) 1997-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#define FLOAT float +#define SET_MANTISSA(flt, mant) \ + do \ + { \ + union ieee754_float u; \ + u.f = (flt); \ + u.ieee_nan.mantissa = (mant); \ + if (u.ieee.mantissa != 0) \ + (flt) = u.f; \ + } \ + while (0) diff --git a/stdlib/strtod_nan_main.c b/stdlib/strtod_nan_main.c new file mode 100644 index 0000000000..bc37a63a27 --- /dev/null +++ b/stdlib/strtod_nan_main.c @@ -0,0 +1,63 @@ +/* Convert string for NaN payload to corresponding NaN. + Copyright (C) 1997-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <ieee754.h> +#include <locale.h> +#include <math.h> +#include <stdlib.h> +#include <wchar.h> + + +/* If STR starts with an optional n-char-sequence as defined by ISO C + (a sequence of ASCII letters, digits and underscores), followed by + ENDC, return a NaN whose payload is set based on STR. Otherwise, + return a default NAN. If ENDPTR is not NULL, set *ENDPTR to point + to the character after the initial n-char-sequence. */ + +internal_function +FLOAT +STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc) +{ + const STRING_TYPE *cp = str; + + while ((*cp >= L_('0') && *cp <= L_('9')) + || (*cp >= L_('A') && *cp <= L_('Z')) + || (*cp >= L_('a') && *cp <= L_('z')) + || *cp == L_('_')) + ++cp; + + FLOAT retval = NAN; + if (*cp != endc) + goto out; + + /* This is a system-dependent way to specify the bitmask used for + the NaN. We expect it to be a number which is put in the + mantissa of the number. */ + STRING_TYPE *endp; + unsigned long long int mant; + + mant = STRTOULL (str, &endp, 0); + if (endp == cp) + SET_MANTISSA (retval, mant); + + out: + if (endptr != NULL) + *endptr = (STRING_TYPE *) cp; + return retval; +} +libc_hidden_def (STRTOD_NAN) diff --git a/stdlib/strtod_nan_narrow.h b/stdlib/strtod_nan_narrow.h new file mode 100644 index 0000000000..bd7704529b --- /dev/null +++ b/stdlib/strtod_nan_narrow.h @@ -0,0 +1,22 @@ +/* Convert string for NaN payload to corresponding NaN. Narrow strings. + Copyright (C) 1997-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#define STRING_TYPE char +#define L_(Ch) Ch +#define STRTOULL(S, E, B) ____strtoull_l_internal ((S), (E), (B), 0, \ + _nl_C_locobj_ptr) diff --git a/stdlib/strtod_nan_wide.h b/stdlib/strtod_nan_wide.h new file mode 100644 index 0000000000..783fbf4796 --- /dev/null +++ b/stdlib/strtod_nan_wide.h @@ -0,0 +1,22 @@ +/* Convert string for NaN payload to corresponding NaN. Wide strings. + Copyright (C) 1997-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#define STRING_TYPE wchar_t +#define L_(Ch) L##Ch +#define STRTOULL(S, E, B) ____wcstoull_l_internal ((S), (E), (B), 0, \ + _nl_C_locobj_ptr) diff --git a/stdlib/strtof_l.c b/stdlib/strtof_l.c index 2a8646a8f6..491256f3b9 100644 --- a/stdlib/strtof_l.c +++ b/stdlib/strtof_l.c @@ -20,26 +20,19 @@ #include <xlocale.h> extern float ____strtof_l_internal (const char *, char **, int, __locale_t); -extern unsigned long long int ____strtoull_l_internal (const char *, char **, - int, int, __locale_t); #define FLOAT float #define FLT FLT #ifdef USE_WIDE_CHAR # define STRTOF wcstof_l # define __STRTOF __wcstof_l +# define STRTOF_NAN __wcstof_nan #else # define STRTOF strtof_l # define __STRTOF __strtof_l +# define STRTOF_NAN __strtof_nan #endif #define MPN2FLOAT __mpn_construct_float #define FLOAT_HUGE_VAL HUGE_VALF -#define SET_MANTISSA(flt, mant) \ - do { union ieee754_float u; \ - u.f = (flt); \ - u.ieee_nan.mantissa = (mant); \ - if (u.ieee.mantissa != 0) \ - (flt) = u.f; \ - } while (0) #include "strtod_l.c" diff --git a/stdlib/strtof_nan.c b/stdlib/strtof_nan.c new file mode 100644 index 0000000000..b971310f7c --- /dev/null +++ b/stdlib/strtof_nan.c @@ -0,0 +1,24 @@ +/* Convert string for NaN payload to corresponding NaN. Narrow + strings, float. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <strtod_nan_narrow.h> +#include <strtod_nan_float.h> + +#define STRTOD_NAN __strtof_nan +#include <strtod_nan_main.c> diff --git a/stdlib/strtold_nan.c b/stdlib/strtold_nan.c new file mode 100644 index 0000000000..dd43032609 --- /dev/null +++ b/stdlib/strtold_nan.c @@ -0,0 +1,30 @@ +/* Convert string for NaN payload to corresponding NaN. Narrow + strings, long double. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> + +/* This function is unused if long double and double have the same + representation. */ +#ifndef __NO_LONG_DOUBLE_MATH +# include <strtod_nan_narrow.h> +# include <strtod_nan_ldouble.h> + +# define STRTOD_NAN __strtold_nan +# include <strtod_nan_main.c> +#endif |