Blame stdlib/strtod_nan_main.c

Packit Service 82fcde
/* Convert string for NaN payload to corresponding NaN.
Packit Service 82fcde
   Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <ieee754.h>
Packit Service 82fcde
#include <locale.h>
Packit Service 82fcde
#include <math.h>
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
#include <wchar.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* If STR starts with an optional n-char-sequence as defined by ISO C
Packit Service 82fcde
   (a sequence of ASCII letters, digits and underscores), followed by
Packit Service 82fcde
   ENDC, return a NaN whose payload is set based on STR.  Otherwise,
Packit Service 82fcde
   return a default NAN.  If ENDPTR is not NULL, set *ENDPTR to point
Packit Service 82fcde
   to the character after the initial n-char-sequence.  */
Packit Service 82fcde
Packit Service 82fcde
FLOAT
Packit Service 82fcde
STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc)
Packit Service 82fcde
{
Packit Service 82fcde
  const STRING_TYPE *cp = str;
Packit Service 82fcde
Packit Service 82fcde
  while ((*cp >= L_('0') && *cp <= L_('9'))
Packit Service 82fcde
	 || (*cp >= L_('A') && *cp <= L_('Z'))
Packit Service 82fcde
	 || (*cp >= L_('a') && *cp <= L_('z'))
Packit Service 82fcde
	 || *cp == L_('_'))
Packit Service 82fcde
    ++cp;
Packit Service 82fcde
Packit Service 82fcde
  FLOAT retval = NAN;
Packit Service 82fcde
  if (*cp != endc)
Packit Service 82fcde
    goto out;
Packit Service 82fcde
Packit Service 82fcde
  /* This is a system-dependent way to specify the bitmask used for
Packit Service 82fcde
     the NaN.  We expect it to be a number which is put in the
Packit Service 82fcde
     mantissa of the number.  */
Packit Service 82fcde
  STRING_TYPE *endp;
Packit Service 82fcde
  unsigned long long int mant;
Packit Service 82fcde
Packit Service 82fcde
  mant = STRTOULL (str, &endp, 0);
Packit Service 82fcde
  if (endp == cp)
Packit Service 82fcde
    SET_NAN_PAYLOAD (retval, mant);
Packit Service 82fcde
Packit Service 82fcde
 out:
Packit Service 82fcde
  if (endptr != NULL)
Packit Service 82fcde
    *endptr = (STRING_TYPE *) cp;
Packit Service 82fcde
  return retval;
Packit Service 82fcde
}
Packit Service 82fcde
libc_hidden_def (STRTOD_NAN)