1 /* Convert string for NaN payload to corresponding NaN.
2 Copyright (C) 1997-2020 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 <https://www.gnu.org/licenses/>. */
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. */
33 STRTOD_NAN (const STRING_TYPE
*str
, STRING_TYPE
**endptr
, STRING_TYPE endc
)
35 const STRING_TYPE
*cp
= str
;
37 while ((*cp
>= L_('0') && *cp
<= L_('9'))
38 || (*cp
>= L_('A') && *cp
<= L_('Z'))
39 || (*cp
>= L_('a') && *cp
<= L_('z'))
47 /* This is a system-dependent way to specify the bitmask used for
48 the NaN. We expect it to be a number which is put in the
49 mantissa of the number. */
51 unsigned long long int mant
;
53 mant
= STRTOULL (str
, &endp
, 0);
55 SET_NAN_PAYLOAD (retval
, mant
);
59 *endptr
= (STRING_TYPE
*) cp
;
62 libc_hidden_def (STRTOD_NAN
)