lua-users home
lua-l archive

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


How about if tonumber() did something like the following. Will work 
if NaN support exists or not.  Will exit() on tonumber("Hello") 
however .... so might need a bit of 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 ) {
    perror( "tonumber()" );
    exit(errno);
  }
  return result;
}