Define HIGH_ORDER_BIT_IS_SET_FOR_SNAN to 0 or 1.
[glibc.git] / stdlib / strtod_nan_main.c
blob10b1be090e9b53972965cf4d7c033819a02b3590
1 /* Convert string for NaN payload to corresponding NaN.
2 Copyright (C) 1997-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <ieee754.h>
20 #include <locale.h>
21 #include <math.h>
22 #include <stdlib.h>
23 #include <wchar.h>
26 /* If STR starts with an optional n-char-sequence as defined by ISO C
27 (a sequence of ASCII letters, digits and underscores), followed by
28 ENDC, return a NaN whose payload is set based on STR. Otherwise,
29 return a default NAN. If ENDPTR is not NULL, set *ENDPTR to point
30 to the character after the initial n-char-sequence. */
32 internal_function
33 FLOAT
34 STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc)
36 const STRING_TYPE *cp = str;
38 while ((*cp >= L_('0') && *cp <= L_('9'))
39 || (*cp >= L_('A') && *cp <= L_('Z'))
40 || (*cp >= L_('a') && *cp <= L_('z'))
41 || *cp == L_('_'))
42 ++cp;
44 FLOAT retval = NAN;
45 if (*cp != endc)
46 goto out;
48 /* This is a system-dependent way to specify the bitmask used for
49 the NaN. We expect it to be a number which is put in the
50 mantissa of the number. */
51 STRING_TYPE *endp;
52 unsigned long long int mant;
54 mant = STRTOULL (str, &endp, 0);
55 if (endp == cp)
56 SET_MANTISSA (retval, mant);
58 out:
59 if (endptr != NULL)
60 *endptr = (STRING_TYPE *) cp;
61 return retval;
63 libc_hidden_def (STRTOD_NAN)