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/>. */
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. */
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'))
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. */
52 unsigned long long int mant
;
54 mant
= STRTOULL (str
, &endp
, 0);
56 SET_MANTISSA (retval
, mant
);
60 *endptr
= (STRING_TYPE
*) cp
;
63 libc_hidden_def (STRTOD_NAN
)