|HP-UX Reference > S
strtod(3C)HP-UX 11i Version 3: February 2007
strtod(), strtof(), strtold(), strtow(), strtoq(), atof() — convert string to floating-point number
double strtod(const char *__restrict str, char **__restrict ptr);
long double strtold(const char *__restrict str, char **__restrict ptr);
double atof(const char *str);
strtod() returns, as a double-precision floating-point number, the value represented by the character string pointed to by str. The string is scanned (leading white-space characters as defined by isspace() in ctype(3C) are ignored) up to the first unrecognized character. If no conversion can take place, zero is returned.
strtod() recognizes characters in the following sequence:
and one of the following:
The radix character is determined by the loaded NLS environment (see setlocale(3C)). If setlocale() has not been called successfully, the default NLS environment, "C", is used (see lang(5)). The default environment specifies a period (.) as the radix character.
In the hexadecimal form, the optionally signed decimal integer following the p or P is interpreted as the power of 2 by which the significant part is to be scaled.
If the value of ptr is not (char **)NULL, the variable to which it points is set to point at the character after the last number, if any, that was recognized. If no number can be formed, *ptr is set to str, and zero is returned.
atof(str) is equivalent to strtod (str, (char **)NULL).
strtold() is a long double version of strtod(); it returns a long double result. For PA-RISC and for Itanium-based systems, if the user has defined _LONG_DOUBLE_STRUCT, the result type is declared as a struct, instead of as a long double. The declaration with a struct is obsolescent.
To use (for Itanium-based systems) strtow() or strtoq(), compile with the -fpwidetypes option.
If the correct value would cause overflow, strtod() returns +/-HUGE_VAL (equal to +/-INFINITY), according to the sign of the value, and sets errno to ERANGE.
If the correct value would be nonzero but too small in magnitude to represent as a nonzero double, then strtod() returns zero and sets errno to ERANGE. For Itanium-based system, strtod() also sets errno to ERANGE whenever the conversion of its input parameter character string to double raises the underflow exception.
When the input parameter character string for strtod(), after the optional white space and sign, is either INF (case insensitive) or INFINITY (case insensitive) strtod() will return +/-INFINITY, according to the sign indicated by the character string.
When the input parameter character string for strtod(), after the optional white space and sign, is NAN (case insensitive), strtod() will return a quiet NaN.
On Itanium-based systems, these functions round correctly for hexadecimal input strings, and round correctly for up to 36 significant decimal digits, according to the specification in ISO/IEC C99.
ctype(3C), setlocale(3C), scanf(3S), strtol(3C), lang(5), thread_safety(5).