WCSTOD(3C) | Standard C Library Functions | WCSTOD(3C) |
#include <wchar.h> double wcstod(const wchar_t *restrict nptr, wchar_t **restrict endptr);
float wcstof(const wchar_t *restrict nptr, wchar_t **restrict endptr);
long double wcstold(const wchar_t *restrict nptr, wchar_t **restrict endptr);
double wstod(const wchar_t *nptr, wchar_t **endptr);
double watof(wchar_t *nptr);
Then they attempt to convert the subject sequence to a floating-point number, and return the result.
The expected form of the subject sequence is an optional plus or minus sign, then one of the following:
n-wchar-sequence: digit nondigit n-wchar-sequence digit n-wchar-sequence nondigit
In default mode for wcstod(), only decimal, INF/INFINITY, and NAN/NAN(n-wchar-sequence) forms are recognized. In C99/SUSv3 mode, hexadecimal strings are also recognized.
In default mode for wcstod(), the n-wchar-sequence in the NAN(n-wchar-sequence) form can contain any character except ')' (right parenthesis) or '\0' (null). In C99/SUSv3 mode, the n-wchar-sequence can contain only upper and lower case letters, digits, and '_' (underscore).
The wcstof() and wcstold() functions always function in C99/SUSv3-conformant mode.
The subject sequence is defined as the longest initial subsequence of the input wide string, starting with the first non-white-space wide character, that is of the expected form. The subject sequence contains no wide 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 wide characters starting with the first digit or the radix character (whichever occurs first) is interpreted as a floating constant according to the rules of the C language, except that the radix character is used in place of a period, and that if neither an exponent part nor a radix character appears in a decimal floating-point number, or if a binary exponent part does not appear in a hexadecimal floating-point number, an exponent part of the appropriate type with value zero 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 wide-character sequence INF or INFINITY is interpreted as an infinity. A wide-character sequence NAN or NAN(n-wchar-sequence(opt)) is interpreted as a quiet NaN. A pointer to the final wide string is stored in the object pointed to by endptr, provided that endptr is not a null pointer.
If the subject sequence has either the decimal or hexadecimal form, the value resulting from the conversion is rounded correctly according to the prevailing floating point rounding direction mode. The conversion also raises floating point inexact, underflow, or overflow exceptions as appropriate.
The radix character is defined in the program's locale (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 ('.').
If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.
The wcstod() function does not change the setting of errno if successful.
The wstod() function is identical to wcstod().
The watof(str) function is equivalent to wstod(nptr, (wchar_t **)NULL).
If the correct value is outside the range of representable values, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned (according to the sign of the value), a floating point overflow exception is raised, and errno is set to ERANGE.
If the correct value would cause an underflow, the correctly rounded result (which may be normal, subnormal, or zero) is returned, a floating point underflow exception is raised, and errno is set to ERANGE.
ERANGE
The wcstod() and wcstod() functions may fail if:
EINVAL
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | wcstod(), wcstof(), and wcstold() are Standard. |
MT-Level | MT-Safe |
August 25, 2019 |