strtod Function (tigcc.a)

AMS 2.00 or higher stdlib.h

double strtod(const char *str, char **endptr);

Converts a string to a floating point value, with optional error-checking.

strtod converts a string pointed to by s to a floating point value. It recognizes the following character representation of a floating point number:

It is easy to "preprocess" any string to satisfy this convention before calling strtod, by code such as the following snippet (assuming that c is a char variable, and i is an integer variable):
for (i = 0; (c = s[i]); i++)
 // Yes, the second '=' is really '=', not '=='...
  {
    if (c == '-') s[i] = 0xAD;
    if ((c|32) == 'e') s[i] = 0x95;
  }
strtod returns the converted value (BCD floating-point number). If endptr is not NULL, the char pointer pointed to by it is assigned the address of the first character of the string following the converted floating-point number. If the conversion fails, 0.0 is returned and *endptr is assigned the value str.
If the result of the conversion would cause overflow, strtod sets errno to ERANGE and returns 9.9999999999999e+999. If the result of the conversion would cause underflow, strtod sets errno to ERANGE and returns 0.

Note: This function is part of AMS, but it is wrapped in the library to prevent a crash when end_ptr == NULL on early AMS 2.xx versions. In fact, atof ends up calling strtod, and using atof takes up more space into your program than strtod does, while not providing the endptr argument, which helps for error checking.


Uses: CTypeTable, errno, push_ulong_to_integer, _bcd_math
Used by: EQU_getNameInfo, push_parse_prgm_or_func_text, cmd_get, push_parse_text


See also: atof, TIOS_strtod