1WCSTOD(3P) POSIX Programmer's Manual WCSTOD(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 wcstod, wcstof, wcstold — convert a wide-character string to a double-
13 precision number
14
16 #include <wchar.h>
17
18 double wcstod(const wchar_t *restrict nptr, wchar_t **restrict endptr);
19 float wcstof(const wchar_t *restrict nptr, wchar_t **restrict endptr);
20 long double wcstold(const wchar_t *restrict nptr,
21 wchar_t **restrict endptr);
22
24 The functionality described on this reference page is aligned with the
25 ISO C standard. Any conflict between the requirements described here
26 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
27 defers to the ISO C standard.
28
29 These functions shall convert the initial portion of the wide-character
30 string pointed to by nptr to double, float, and long double representa‐
31 tion, respectively. First, they shall decompose the input wide-charac‐
32 ter string into three parts:
33
34 1. An initial, possibly empty, sequence of white-space wide-character
35 codes (as specified by iswspace())
36
37 2. A subject sequence interpreted as a floating-point constant or rep‐
38 resenting infinity or NaN
39
40 3. A final wide-character string of one or more unrecognized wide-
41 character codes, including the terminating null wide-character code
42 of the input wide-character string
43
44 Then they shall attempt to convert the subject sequence to a floating-
45 point number, and return the result.
46
47 The expected form of the subject sequence is an optional '+' or '-'
48 sign, then one of the following:
49
50 * A non-empty sequence of decimal digits optionally containing a
51 radix character; then an optional exponent part consisting of the
52 wide character 'e' or the wide character 'E', optionally followed
53 by a '+' or '-' wide character, and then followed by one or more
54 decimal digits
55
56 * A 0x or 0X, then a non-empty sequence of hexadecimal digits option‐
57 ally containing a radix character; then an optional binary exponent
58 part consisting of the wide character 'p' or the wide character
59 'P', optionally followed by a '+' or '-' wide character, and then
60 followed by one or more decimal digits
61
62 * One of INF or INFINITY, or any other wide string equivalent except
63 for case
64
65 * One of NAN or NAN(n-wchar-sequenceopt), or any other wide string
66 ignoring case in the NAN part, where:
67
68
69 n-wchar-sequence:
70 digit
71 nondigit
72 n-wchar-sequence digit
73 n-wchar-sequence nondigit
74
75 The subject sequence is defined as the longest initial subsequence of
76 the input wide string, starting with the first non-white-space wide
77 character, that is of the expected form. The subject sequence contains
78 no wide characters if the input wide string is not of the expected
79 form.
80
81 If the subject sequence has the expected form for a floating-point num‐
82 ber, the sequence of wide characters starting with the first digit or
83 the radix character (whichever occurs first) shall be interpreted as a
84 floating constant according to the rules of the C language, except that
85 the radix character shall be used in place of a period, and that if
86 neither an exponent part nor a radix character appears in a decimal
87 floating-point number, or if a binary exponent part does not appear in
88 a hexadecimal floating-point number, an exponent part of the appropri‐
89 ate type with value zero shall be assumed to follow the last digit in
90 the string. If the subject sequence begins with a <hyphen-minus>, the
91 sequence shall be interpreted as negated. A wide-character sequence INF
92 or INFINITY shall be interpreted as an infinity, if representable in
93 the return type, else as if it were a floating constant that is too
94 large for the range of the return type. A wide-character sequence NAN
95 or NAN(n-wchar-sequenceopt) shall be interpreted as a quiet NaN, if
96 supported in the return type, else as if it were a subject sequence
97 part that does not have the expected form; the meaning of the n-wchar
98 sequences is implementation-defined. A pointer to the final wide string
99 shall be stored in the object pointed to by endptr, provided that
100 endptr is not a null pointer.
101
102 If the subject sequence has the hexadecimal form and FLT_RADIX is a
103 power of 2, the conversion shall be rounded in an implementation-
104 defined manner.
105
106 The radix character shall be as defined in the current locale (category
107 LC_NUMERIC). In the POSIX locale, or in a locale where the radix char‐
108 acter is not defined, the radix character shall default to a <period>
109 ('.').
110
111 In other than the C or POSIX locale, additional locale-specific subject
112 sequence forms may be accepted.
113
114 If the subject sequence is empty or does not have the expected form, no
115 conversion shall be performed; the value of nptr shall be stored in the
116 object pointed to by endptr, provided that endptr is not a null
117 pointer.
118
119 These functions shall not change the setting of errno if successful.
120
121 Since 0 is returned on error and is also a valid return on success, an
122 application wishing to check for error situations should set errno to
123 0, then call wcstod(), wcstof(), or wcstold(), then check errno.
124
126 Upon successful completion, these functions shall return the converted
127 value. If no conversion could be performed, 0 shall be returned and
128 errno may be set to [EINVAL].
129
130 If the correct value is outside the range of representable values,
131 ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL shall be returned (according to
132 the sign of the value), and errno shall be set to [ERANGE].
133
134 If the correct value would cause underflow, a value whose magnitude is
135 no greater than the smallest normalized positive number in the return
136 type shall be returned and errno set to [ERANGE].
137
139 The wcstod() function shall fail if:
140
141 ERANGE The value to be returned would cause overflow or underflow.
142
143 The wcstod() function may fail if:
144
145 EINVAL No conversion could be performed.
146
147 The following sections are informative.
148
150 None.
151
153 If the subject sequence has the hexadecimal form and FLT_RADIX is not a
154 power of 2, and the result is not exactly representable, the result
155 should be one of the two numbers in the appropriate internal format
156 that are adjacent to the hexadecimal floating source value, with the
157 extra stipulation that the error should have a correct sign for the
158 current rounding direction.
159
160 If the subject sequence has the decimal form and at most DECIMAL_DIG
161 (defined in <float.h>) significant digits, the result should be cor‐
162 rectly rounded. If the subject sequence D has the decimal form and more
163 than DECIMAL_DIG significant digits, consider the two bounding, adja‐
164 cent decimal strings L and U, both having DECIMAL_DIG significant dig‐
165 its, such that the values of L, D, and U satisfy "L<=D<=U". The result
166 should be one of the (equal or adjacent) values that would be obtained
167 by correctly rounding L and U according to the current rounding direc‐
168 tion, with the extra stipulation that the error with respect to D
169 should have a correct sign for the current rounding direction.
170
172 None.
173
175 None.
176
178 fscanf(), iswspace(), localeconv(), setlocale(), wcstol()
179
180 The Base Definitions volume of POSIX.1‐2017, Chapter 7, Locale,
181 <float.h>, <wchar.h>
182
184 Portions of this text are reprinted and reproduced in electronic form
185 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
186 table Operating System Interface (POSIX), The Open Group Base Specifi‐
187 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
188 Electrical and Electronics Engineers, Inc and The Open Group. In the
189 event of any discrepancy between this version and the original IEEE and
190 The Open Group Standard, the original IEEE and The Open Group Standard
191 is the referee document. The original Standard can be obtained online
192 at http://www.opengroup.org/unix/online.html .
193
194 Any typographical or formatting errors that appear in this page are
195 most likely to have been introduced during the conversion of the source
196 files to man page format. To report such errors, see https://www.ker‐
197 nel.org/doc/man-pages/reporting_bugs.html .
198
199
200
201IEEE/The Open Group 2017 WCSTOD(3P)