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
11
13 wcstod, wcstof, wcstold — convert a wide-character string to a double-
14 precision number
15
17 #include <wchar.h>
18
19 double wcstod(const wchar_t *restrict nptr, wchar_t **restrict endptr);
20 float wcstof(const wchar_t *restrict nptr, wchar_t **restrict endptr);
21 long double wcstold(const wchar_t *restrict nptr,
22 wchar_t **restrict endptr);
23
25 The functionality described on this reference page is aligned with the
26 ISO C standard. Any conflict between the requirements described here
27 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
28 defers to the ISO C standard.
29
30 These functions shall convert the initial portion of the wide-character
31 string pointed to by nptr to double, float, and long double representa‐
32 tion, respectively. First, they shall decompose the input wide-charac‐
33 ter string into three parts:
34
35 1. An initial, possibly empty, sequence of white-space wide-character
36 codes (as specified by iswspace())
37
38 2. A subject sequence interpreted as a floating-point constant or rep‐
39 resenting infinity or NaN
40
41 3. A final wide-character string of one or more unrecognized wide-
42 character codes, including the terminating null wide-character code
43 of the input wide-character string
44
45 Then they shall attempt to convert the subject sequence to a floating-
46 point number, and return the result.
47
48 The expected form of the subject sequence is an optional '+' or '−'
49 sign, then one of the following:
50
51 * A non-empty sequence of decimal digits optionally containing a
52 radix character; then an optional exponent part consisting of the
53 wide character 'e' or the wide character 'E', optionally followed
54 by a '+' or '−' wide character, and then followed by one or more
55 decimal digits
56
57 * A 0x or 0X, then a non-empty sequence of hexadecimal digits option‐
58 ally containing a radix character; then an optional binary exponent
59 part consisting of the wide character 'p' or the wide character
60 'P', optionally followed by a '+' or '−' wide character, and then
61 followed by one or more decimal digits
62
63 * One of INF or INFINITY, or any other wide string equivalent except
64 for case
65
66 * One of NAN or NAN(n-wchar-sequenceopt), or any other wide string
67 ignoring case in the NAN part, where:
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 minus-sign, 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 locales, other implementation-defined sub‐
112 ject sequences 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‐2008, 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, 2013 Edition, Standard for Information Technology
186 -- Portable Operating System Interface (POSIX), The Open Group Base
187 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
188 cal and Electronics Engineers, Inc and The Open Group. (This is
189 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
190 event of any discrepancy between this version and the original IEEE and
191 The Open Group Standard, the original IEEE and The Open Group Standard
192 is the referee document. The original Standard can be obtained online
193 at http://www.unix.org/online.html .
194
195 Any typographical or formatting errors that appear in this page are
196 most likely to have been introduced during the conversion of the source
197 files to man page format. To report such errors, see https://www.ker‐
198 nel.org/doc/man-pages/reporting_bugs.html .
199
200
201
202IEEE/The Open Group 2013 WCSTOD(3P)