lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If I'm going to give code examples I better make sure they work :-)

double tonumber( const char *str )
{
  double result;
  char *endptr = (char*)str;
  
  if( str != NULL ) {
    errno=0;
    result = strtod( str, &endptr );
  }
  if( endptr == str )
    errno = EINVAL;
  if( errno != 0 && errno != ERANGE ) {
    perror( "tonumber()" );
    exit(errno);
  }
  return result;
}