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