src/lobject.c
static lua_Number lua_strx2number (const char *s, char **endptr) {
  int dot = lua_getlocaledecpoint();
  lua_Number r = 0.0;  /* result (accumulator) */
  int sigdig = 0;  /* number of significant digits */
  int nosigdig = 0;  /* number of non-significant digits */
  int e = 0;  /* exponent correction */
  int neg;  /* 1 if number is negative */
  int hasdot = 0;  /* true after seen a dot */
  *endptr = cast_charp(s);  /* nothing is valid yet */
  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */
  neg = isneg(&s);  /* check sign */
  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */
    return 0.0;  /* invalid format (no '0x') */
  for (s += 2; ; s++) {  /* skip '0x' and read numeral */
    if (*s == dot) {
      if (hasdot) break;  /* second dot? stop loop */
      else hasdot = 1;
    }
    else if (lisxdigit(cast_uchar(*s))) {
      if (sigdig == 0 && *s == '0')  /* non-significant digit (zero)? */
        nosigdig++;
      else if (++sigdig <= MAXSIGDIG)  /* can read it without overflow? */
          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);
      else e++; /* too many digits; ignore, but still count for exponent */
      if (hasdot) e--;  /* decimal digit? correct exponent */
    }
    else break;  /* neither a dot nor a digit */
  }
  if (nosigdig + sigdig == 0)  /* no digits? */
    return 0.0;  /* invalid format */
  *endptr = cast_charp(s);  /* valid up to here */
  e *= 4;  /* each digit multiplies/divides value by 2^4 */
  if (*s == 'p' || *s == 'P') {  /* exponent part? */
    int exp1 = 0;  /* exponent value */
    int neg1;  /* exponent sign */
    s++;  /* skip 'p' */
    neg1 = isneg(&s);  /* sign */
    if (!lisdigit(cast_uchar(*s)))
      return 0.0;  /* invalid; must have at least one digit */
    while (lisdigit(cast_uchar(*s)))  /* read exponent */
      exp1 = exp1 * 10 + *(s++) - '0';
    if (neg1) exp1 = -exp1;
    e += exp1;
    *endptr = cast_charp(s);  /* valid up to here */
  }
  if (neg) r = -r;
  return l_mathop(ldexp)(r, e);
}
/*
** convert a hexadecimal numeric string to a number, following
** C99 specification for 'strtod'
*/
convert a hexadecimal numeric string to a number, following
C99 specification for 'strtod'
convert a hexadecimal numeric string to a number following C99 specification for ' strtod '
static lua_Number lua_strx2number (const char *s, char **endptr) {
  int dot = lua_getlocaledecpoint();
  lua_Number r = 0.0;  
  int sigdig = 0;  
  int nosigdig = 0;  
  int e = 0;  
  int neg;  
  int hasdot = 0;  
  *endptr = cast_charp(s);  
  while (lisspace(cast_uchar(*s))) s++;  
  neg = isneg(&s);  
  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  
    return 0.0;  
  for (s += 2; ; s++) {  
    if (*s == dot) {
      if (hasdot) break;  
      else hasdot = 1;
    }
    else if (lisxdigit(cast_uchar(*s))) {
      if (sigdig == 0 && *s == '0')  
        nosigdig++;
      else if (++sigdig <= MAXSIGDIG)  
          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);
      else e++; 
      if (hasdot) e--;  
    }
    else break;  
  }
  if (nosigdig + sigdig == 0)  
    return 0.0;  
  *endptr = cast_charp(s);  
  e *= 4;  
  if (*s == 'p' || *s == 'P') {  
    int exp1 = 0;  
    int neg1;  
    s++;  
    neg1 = isneg(&s);  
    if (!lisdigit(cast_uchar(*s)))
      return 0.0;  
    while (lisdigit(cast_uchar(*s)))  
      exp1 = exp1 * 10 + *(s++) - '0';
    if (neg1) exp1 = -exp1;
    e += exp1;
    *endptr = cast_charp(s);  
  }
  if (neg) r = -r;
  return l_mathop(ldexp)(r, e);
}
static lua_Number lua_strx2number ( const char * s , char * * endptr ) { int dot = lua_getlocaledecpoint ( ) ; lua_Number r = 0.0 ; int sigdig = 0 ; int nosigdig = 0 ; int e = 0 ; int neg ; int hasdot = 0 ; * endptr = cast_charp ( s ) ; while ( lisspace ( cast_uchar ( * s ) ) ) s ++ ; neg = isneg ( & s ) ; if ( ! ( * s == ' ' && ( * ( s + 1 ) == ' ' || * ( s + 1 ) == ' ' ) ) ) return 0.0 ; for ( s += 2 ; ; s ++ ) { if ( * s == dot ) { if ( hasdot ) break ; else hasdot = 1 ; } else if ( lisxdigit ( cast_uchar ( * s ) ) ) { if ( sigdig == 0 && * s == ' ' ) nosigdig ++ ; else if ( ++ sigdig <= MAXSIGDIG ) r = ( r * cast_num ( 16.0 ) ) + luaO_hexavalue ( * s ) ; else e ++ ; if ( hasdot ) e -- ; } else break ; } if ( nosigdig + sigdig == 0 ) return 0.0 ; * endptr = cast_charp ( s ) ; e *= 4 ; if ( * s == ' ' || * s == ' ' ) { int exp1 = 0 ; int neg1 ; s ++ ; neg1 = isneg ( & s ) ; if ( ! lisdigit ( cast_uchar ( * s ) ) ) return 0.0 ; while ( lisdigit ( cast_uchar ( * s ) ) ) exp1 = exp1 * 10 + * ( s ++ ) - ' ' ; if ( neg1 ) exp1 = - exp1 ; e += exp1 ; * endptr = cast_charp ( s ) ; } if ( neg ) r = - r ; return l_mathop ( ldexp ) ( r , e ) ; }
convert a hexadecimal numeric string to a number, following
C99 specification for 'strtod'
convert a hexadecimal numeric string to a number following C99 specification for ' strtod '
/* result (accumulator) */ /* number of significant digits */ /* number of non-significant digits */ /* exponent correction */ /* 1 if number is negative */ /* true after seen a dot */ /* nothing is valid yet */ /* skip initial spaces */ /* check sign */ /* check '0x' */ /* invalid format (no '0x') */ /* skip '0x' and read numeral */ /* second dot? stop loop */ /* non-significant digit (zero)? */ /* can read it without overflow? */ /* too many digits; ignore, but still count for exponent */ /* decimal digit? correct exponent */ /* neither a dot nor a digit */ /* no digits? */ /* invalid format */ /* valid up to here */ /* each digit multiplies/divides value by 2^4 */ /* exponent part? */ /* exponent value */ /* exponent sign */ /* skip 'p' */ /* sign */ /* invalid; must have at least one digit */ /* read exponent */ /* valid up to here */