These functions are declared in `stdlib.h'.
strtod
(``string-to-double'') function converts the initial part of string to a floating-point number, which is returned as a value of type double
. This function attempts to decompose string as follows:
A (possibly empty) sequence of whitespace characters. Which characters are whitespace is determined by the isspace
function (see Classification of Characters). These are discarded.
An optional plus or minus sign (`+' or `-').
A nonempty sequence of digits optionally containing a decimal-point character---normally `.', but it depends on the locale (see Numeric Formatting).
An optional exponent part, consisting of a character `e' or `E', an optional sign, and a sequence of digits.
Any remaining characters in the string. If tailptr is not a null pointer, a pointer to this tail of the string is stored in *tailptr
.
If the string is empty, contains only whitespace, or does not contain an initial substring that has the expected syntax for a floating-point number, no conversion is performed. In this case, strtod
returns a value of zero and the value returned in *tailptr
is the value of string.
In a locale other than the standard "C"
locale, this function may recognize additional locale-dependent syntax.
If the string has valid syntax for a floating-point number but the value is not representable because of overflow, strtod
returns either positive or negative HUGE_VAL
(see Mathematics), depending on the sign of the value. Similarly, if the value is not representable because of underflow, strtod
returns zero. It also sets errno
to ERANGE
if there was overflow or underflow.
strtod
function, except that it need not detect overflow and underflow errors. The atof
function is provided mostly for compatibility with existing code; using strtod
is more robust.