WCSTOD(3C) Standard C Library Functions WCSTOD(3C)
NNAAMMEE
wcstod, wcstof, wcstold, wstod, watof - convert wide character string
to floating-point number
SSYYNNOOPPSSIISS
#include
ddoouubbllee wwccssttoodd(ccoonnsstt wwcchhaarr__tt **rreessttrriicctt _n_p_t_r,
wwcchhaarr__tt ****rreessttrriicctt _e_n_d_p_t_r);
ffllooaatt wwccssttooff(ccoonnsstt wwcchhaarr__tt **rreessttrriicctt _n_p_t_r,
wwcchhaarr__tt ****rreessttrriicctt _e_n_d_p_t_r);
lloonngg ddoouubbllee wwccssttoolldd(ccoonnsstt wwcchhaarr__tt **rreessttrriicctt _n_p_t_r,
wwcchhaarr__tt ****rreessttrriicctt _e_n_d_p_t_r);
ddoouubbllee wwssttoodd(ccoonnsstt wwcchhaarr__tt **_n_p_t_r, wwcchhaarr__tt ****_e_n_d_p_t_r);
ddoouubbllee wwaattooff(wwcchhaarr__tt **_n_p_t_r);
DDEESSCCRRIIPPTTIIOONN
The wwccssttoodd(()), wwccssttooff(()), and wwccssttoolldd(()) functions convert the initial
portion of the wide-character string pointed to by _n_p_t_r to ddoouubbllee,
ffllooaatt, and lloonngg ddoouubbllee representation, respectively. They first
decompose the input wide-character string into three parts:
1. An initial, possibly empty, sequence of white-space wide-
character codes (as specified by iisswwssppaaccee(3C))
2. A subject sequence interpreted as a floating-point constant
or representing infinity or NaN
3. A final wide-character string of one or more unrecognized
wide-character codes, including the terminating null wide-
character code of the input wide-character string.
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:
o A non-empty sequence of decimal digits optionally containing
a radix character, then an optional exponent part
o A 0x or 0X, then a non-empty sequence of hexadecimal digits
optionally containing a radix character, then an optional
binary exponent part
o One of INF or INFINITY, or any other wide string equivalent
except for case
o One of NAN or NAN(_n_-_w_c_h_a_r_-_s_e_q_u_e_n_c_e(_o_p_t)), or any other wide
string ignoring case in the NAN part, where:
n-wchar-sequence:
digit
nondigit
n-wchar-sequence digit
n-wchar-sequence nondigit
In default mode for wwccssttoodd(()), only decimal, INF/INFINITY, and
NAN/NAN(_n_-_w_c_h_a_r_-_s_e_q_u_e_n_c_e) forms are recognized. In C99/SUSv3 mode,
hexadecimal strings are also recognized.
In default mode for wwccssttoodd(()), the _n_-_w_c_h_a_r_-_s_e_q_u_e_n_c_e in the NAN(_n_-_w_c_h_a_r_-
_s_e_q_u_e_n_c_e) form can contain any character except ')' (right parenthesis)
or '\0' (null). In C99/SUSv3 mode, the _n_-_w_c_h_a_r_-_s_e_q_u_e_n_c_e can contain
only upper and lower case letters, digits, and '_' (underscore).
The wwccssttooff(()) and wwccssttoolldd(()) 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_-
_w_c_h_a_r_-_s_e_q_u_e_n_c_e(_o_p_t)) is interpreted as a quiet NaN. A pointer to the
final wide string is stored in the object pointed to by _e_n_d_p_t_r,
provided that _e_n_d_p_t_r 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
LLCC__NNUUMMEERRIICC). 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 _n_p_t_r is stored in the object
pointed to by _e_n_d_p_t_r, provided that _e_n_d_p_t_r is not a null pointer.
The wwccssttoodd(()) function does not change the setting of eerrrrnnoo if
successful.
The wwssttoodd(()) function is identical to wwccssttoodd(()).
The wwaattooff(_s_t_r) function is equivalent to wwssttoodd((_n_p_t_r,, ((wwcchhaarr__tt ****))NNUULLLL)).
RREETTUURRNN VVAALLUUEESS
Upon successful completion, these functions return the converted value.
If no conversion could be performed, 00 is returned.
If the correct value is outside the range of representable values,
++--HHUUGGEE__VVAALL, ++--HHUUGGEE__VVAALLFF, or ++--HHUUGGEE__VVAALLLL is returned (according to the
sign of the value), a floating point overflow exception is raised, and
eerrrrnnoo is set to EERRAANNGGEE.
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 eerrrrnnoo is set to
EERRAANNGGEE.
EERRRROORRSS
The wwccssttoodd(()) and wwssttoodd(()) functions will fail if:
EERRAANNGGEE
The value to be returned would cause overflow or underflow.
The wwccssttoodd(()) and wwccssttoodd(()) functions may fail if:
EEIINNVVAALL
No conversion could be performed.
UUSSAAGGEE
Because 0 is returned on error and is also a valid return on success,
an application wishing to check for error situations should set eerrrrnnoo
to 0 call wwccssttoodd(()), wwccssttooff(()), wwccssttoolldd(()), or wwssttoodd(()), then check eerrrrnnoo
and if it is non-zero, assume an error has occurred.
AATTTTRRIIBBUUTTEESS
See aattttrriibbuutteess(5) for descriptions of the following attributes:
+--------------------+-------------------------+
|ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+--------------------+-------------------------+
|Interface Stability | wwccssttoodd(()), wwccssttooff(()), and |
| | wwccssttoolldd(()) are Standard. |
+--------------------+-------------------------+
|MT-Level | MT-Safe |
+--------------------+-------------------------+
SSEEEE AALLSSOO
iisswwssppaaccee(3C), llooccaalleeccoonnvv(3C), ssccaannff(3C), sseettllooccaallee(3C), wwccssttooll(3C),
aattttrriibbuutteess(5), ssttaannddaarrddss(5)
August 25, 2019 WCSTOD(3C)