pandas/src/parser/tokenizer.c
//
// strtod.c
//
// Convert string to double
//
// Copyright (C) 2002 Michael Ringgaard. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
// 3. Neither the name of the project nor the names of its contributors
//    may be used to endorse or promote products derived from this software
//    without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// -----------------------------------------------------------------------
// Modifications by Warren Weckesser, March 2011:
// * Rename strtod() to xstrtod().
// * Added decimal and sci arguments.
// * Skip trailing spaces.
// * Commented out the other functions.
// Modifications by Richard T Guy, August 2013:
// * Add tsep argument for thousands separator
//
strtod.c
Convert string to double



Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met.

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.



Modifications by Warren Weckesser, March 2011:
Rename strtod() to xstrtod().
Added decimal and sci arguments.
Skip trailing spaces.
Commented out the other functions.
Modifications by Richard T Guy, August 2013:
Add tsep argument for thousands separator
strtod . c Convert string to double Redistribution and use in source and binary forms with or without modification are permitted provided that the following conditions are met . 1 . Redistributions of source code must retain the above copyright notice this list of conditions and the following disclaimer . 2 . Redistributions in binary form must reproduce the above copyright notice this list of conditions and the following disclaimer in the documentation and / or other materials provided with the distribution . 3 . Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission . Modifications by Warren Weckesser March 2011 : Rename strtod () to xstrtod () . Added decimal and sci arguments . Skip trailing spaces . Commented out the other functions . Modifications by Richard T Guy August 2013 : Add tsep argument for thousands separator
static double xstrtod(const char *str, char **endptr, char decimal,
                      char sci, char tsep, int skip_trailing)
{
  double number;
  int exponent;
  int negative;
  char *p = (char *) str;
  double p10;
  int n;
  int num_digits;
  int num_decimals;
  errno = 0;
  while (isspace(*p)) p++;
  negative = 0;
  switch (*p)
  {
    case '-': negative = 1; 
    case '+': p++;
  }
  number = 0.;
  exponent = 0;
  num_digits = 0;
  num_decimals = 0;
  while (isdigit(*p))
  {
    number = number * 10. + (*p - '0');
    p++;
    num_digits++;
    p += (tsep != '\0' & *p == tsep);
  }
  if (*p == decimal)
  {
    p++;
    while (isdigit(*p))
    {
      number = number * 10. + (*p - '0');
      p++;
      num_digits++;
      num_decimals++;
    }
    exponent -= num_decimals;
  }
  if (num_digits == 0)
  {
    errno = ERANGE;
    return 0.0;
  }
  if (negative) number = -number;
  if (toupper(*p) == toupper(sci))
  {
    negative = 0;
    switch (*++p)
    {
      case '-': negative = 1;   
      case '+': p++;
    }
    n = 0;
    while (isdigit(*p))
    {
      n = n * 10 + (*p - '0');
      p++;
    }
    if (negative)
      exponent -= n;
    else
      exponent += n;
  }
  if (exponent < DBL_MIN_EXP  || exponent > DBL_MAX_EXP)
  {
    errno = ERANGE;
    return HUGE_VAL;
  }
  p10 = 10.;
  n = exponent;
  if (n < 0) n = -n;
  while (n)
  {
    if (n & 1)
    {
      if (exponent < 0)
        number /= p10;
      else
        number *= p10;
    }
    n >>= 1;
    p10 *= p10;
  }
  if (number == HUGE_VAL) {
      errno = ERANGE;
  }
  if (skip_trailing) {
      while (isspace(*p)) p++;
  }
  if (endptr) *endptr = p;
  return number;
}
static double xstrtod ( const char * str , char * * endptr , char decimal , char sci , char tsep , int skip_trailing ) { double number ; int exponent ; int negative ; char * p = ( char * ) str ; double p10 ; int n ; int num_digits ; int num_decimals ; errno = 0 ; while ( isspace ( * p ) ) p ++ ; negative = 0 ; switch ( * p ) { case ' ' : negative = 1 ; case ' ' : p ++ ; } number = 0. ; exponent = 0 ; num_digits = 0 ; num_decimals = 0 ; while ( isdigit ( * p ) ) { number = number * 10. + ( * p - ' ' ) ; p ++ ; num_digits ++ ; p += ( tsep != ' \0 ' & * p == tsep ) ; } if ( * p == decimal ) { p ++ ; while ( isdigit ( * p ) ) { number = number * 10. + ( * p - ' ' ) ; p ++ ; num_digits ++ ; num_decimals ++ ; } exponent -= num_decimals ; } if ( num_digits == 0 ) { errno = ERANGE ; return 0.0 ; } if ( negative ) number = - number ; if ( toupper ( * p ) == toupper ( sci ) ) { negative = 0 ; switch ( * ++ p ) { case ' ' : negative = 1 ; case ' ' : p ++ ; } n = 0 ; while ( isdigit ( * p ) ) { n = n * 10 + ( * p - ' ' ) ; p ++ ; } if ( negative ) exponent -= n ; else exponent += n ; } if ( exponent < DBL_MIN_EXP || exponent > DBL_MAX_EXP ) { errno = ERANGE ; return HUGE_VAL ; } p10 = 10. ; n = exponent ; if ( n < 0 ) n = - n ; while ( n ) { if ( n & 1 ) { if ( exponent < 0 ) number /= p10 ; else number *= p10 ; } n >>= 1 ; p10 *= p10 ; } if ( number == HUGE_VAL ) { errno = ERANGE ; } if ( skip_trailing ) { while ( isspace ( * p ) ) p ++ ; } if ( endptr ) * endptr = p ; return number ; }
strtod.c
Convert string to double
strtod . c Convert string to double
// Skip leading whitespace // Handle optional sign // Fall through to increment position // Process string of digits // Process decimal part // Correct for sign // Process an exponent string // Handle optional sign // Fall through to increment pos // Process string of digits // Scale the result // Skip trailing whitespace