Converts a string to a decimal floating-point number.
Standard C Library (libc.a)
#include <stdlib.h>
_Decimal32 strtod32 (nptr, endptr)
const char *nptr;
char **endptr;
_Decimal64 strtod64 (nptr, endptr)
const char *nptr;
char **endptr;
_Decimal128 strtod128 (nptr, endptr)
const char *nptr;
char **endptr;
n-char-sequence:
digit
n-char-sequence digit
The subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-white-space character that is of the expected form. The subject sequence contains no characters if the input wide string is not of the expected form.
If the subject sequence has the expected form for a floating-point number, the sequence of characters starting with the first digit or the radix character (whichever occurs first) are interpreted as a floating constant according to the rules of the C language, except that the sequence is not a hexadecimal floating number or the radix character is used in place of a period. If neither an exponent part nor a radix character appears in a decimal floating-point number, an exponent part of the appropriate type with a value of 0 is assumed to follow the last digit in the string.
If the subject sequence begins with a minus sign, the sequence is interpreted as negated. A character sequence INF or INFINITY is interpreted as infinity. A character sequence NAN or NAN (n-char-sequence opt) is interpreted as a quiet NaN. The meaning of the n-char sequences is implementation-defined. A pointer to the final string is stored in the object pointed to by the endptr parameter, provided that the endptr parameter is not a null pointer.
The radix character is defined in the locale of the program (category LC_NUMERIC). In the POSIX locale, or in a locale where the radix character is not defined, the radix character defaults to a period.
In locales other than the C or POSIX locale, other implementation-defined subject sequences can be accepted.
If the subject sequence is empty or does not have the expected form, no conversion is performed. The value of the nptr parameter is stored in the object pointed to by the endptr parameter , provided that the endptr parameter is not a null pointer.
The strtod32, strtod64, and strtod128 subroutines do not change the setting of the errno global variable if successful.
The value of 0 is returned on error and it is also a valid return value on success. Therefore, an application checking for error situations must set the value of the errno global variable to 0, call the strtod32, strtod64, or strto128 subroutine, and check the errno global variable.
Item | Description |
---|---|
nptr | Contains a pointer to the string to be converted to a decimal floating point value. |
endpr | Contains a pointer to the position in the string specified by the nptr parameter where a character is found that is not a valid character for the conversion. |
Upon successful completion, the strtod32, strtod64, and strtod128 subroutines return the converted value. If no conversion can be performed, the value of 0 is returned and the errno global variable might be set to EINVAL.
If the correct value is outside the range of representable values, ±HUGE_VAL_D32, ±HUGE_VAL_D64, or ±HUGE_VAL_D128 is returned (according to the return type and sign of the value), and the errno global variable is set to ERANGE.
If the correct value causes underflow, a value whose magnitude is no greater than the smallest normalized positive number in the return type is returned, and the errno global variable is set to ERANGE.