1WCSTOD(3P)                 POSIX Programmer's Manual                WCSTOD(3P)
2
3
4

PROLOG

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

NAME

12       wcstod, wcstof, wcstold - convert a wide-character string to a  double-
13       precision number
14

SYNOPSIS

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
23

DESCRIPTION

25       These functions shall convert the initial portion of the wide-character
26       string pointed to by nptr to double, float, and long double representa‐
27       tion,  respectively. First, they shall decompose the input wide-charac‐
28       ter string into three parts:
29
30        1. An initial, possibly empty, sequence of white-space  wide-character
31           codes (as specified by iswspace())
32
33        2. A subject sequence interpreted as a floating-point constant or rep‐
34           resenting infinity or NaN
35
36        3. A final wide-character string of one  or  more  unrecognized  wide-
37           character codes, including the terminating null wide-character code
38           of the input wide-character string
39
40       Then they shall attempt to convert the subject sequence to a  floating-
41       point number, and return the result.
42
43       The  expected form of the subject sequence is an optional plus or minus
44       sign, then one of the following:
45
46        * A non-empty sequence of decimal digits optionally containing a radix
47          character, then an optional exponent part
48
49        * A  0x or 0X, then a non-empty sequence of hexadecimal digits option‐
50          ally containing a radix character, then an optional binary  exponent
51          part
52
53        * One  of  INF or INFINITY, or any other wide string equivalent except
54          for case
55
56        * One of NAN or NAN(n-wchar-sequence_opt), or any  other  wide  string
57          ignoring case in the NAN part, where:
58
59
60          n-wchar-sequence:
61              digit
62              nondigit
63              n-wchar-sequence digit
64              n-wchar-sequence nondigit
65
66       The  subject  sequence is defined as the longest initial subsequence of
67       the input wide string, starting with  the  first  non-white-space  wide
68       character,  that is of the expected form. The subject sequence contains
69       no wide characters if the input wide string  is  not  of  the  expected
70       form.
71
72       If the subject sequence has the expected form for a floating-point num‐
73       ber, the sequence of wide characters starting with the first  digit  or
74       the  radix character (whichever occurs first) shall be interpreted as a
75       floating constant according to the rules of the C language, except that
76       the  radix  character  shall  be used in place of a period, and that if
77       neither an exponent part nor a radix character  appears  in  a  decimal
78       floating-point  number, or if a binary exponent part does not appear in
79       a hexadecimal floating-point number, an exponent part of the  appropri‐
80       ate  type  with value zero shall be assumed to follow the last digit in
81       the string. If the subject sequence  begins  with  a  minus  sign,  the
82       sequence shall be interpreted as negated. A wide-character sequence INF
83       or INFINITY shall be interpreted as an infinity,  if  representable  in
84       the  return  type,  else  as if it were a floating constant that is too
85       large for the range of the return type. A wide-character  sequence  NAN
86       or  NAN(n-wchar-sequence_opt)  shall  be interpreted as a quiet NaN, if
87       supported in the return type, else as if it  were  a  subject  sequence
88       part  that  does not have the expected form; the meaning of the n-wchar
89       sequences is implementation-defined. A pointer to the final wide string
90       shall  be  stored  in  the  object  pointed to by endptr, provided that
91       endptr is not a null pointer.
92
93       If the subject sequence has the hexadecimal form  and  FLT_RADIX  is  a
94       power  of  2,  the  conversion  shall  be rounded in an implementation-
95       defined manner.
96
97       The radix character shall be as defined in the program's locale  (cate‐
98       gory  LC_NUMERIC ). In the POSIX locale, or in a locale where the radix
99       character is not defined, the radix character shall default to a period
100       ( '.' ).
101
102       In  other  than  the C  or POSIX  locales, other implementation-defined
103       subject sequences may be accepted.
104
105       If the subject sequence is empty or does not have the expected form, no
106       conversion shall be performed; the value of nptr shall be stored in the
107       object pointed to by  endptr,  provided  that  endptr  is  not  a  null
108       pointer.
109
110       The wcstod() function shall not change the setting of errno if success‐
111       ful.
112
113       Since 0 is returned on error and is also a valid return on success,  an
114       application  wishing  to check for error situations should set errno to
115       0, then call wcstod(), wcstof(), or wcstold(), then check errno.
116

RETURN VALUE

118       Upon successful completion, these functions shall return the  converted
119       value.  If  no  conversion could be performed, 0 shall be returned  and
120       errno may be set to [EINVAL].
121
122       If the correct value is outside  the  range  of  representable  values,
123       ±HUGE_VAL,  ±HUGE_VALF,  or  ±HUGE_VALL shall be returned (according to
124       the sign of the value), and errno shall be set to [ERANGE].
125
126       If the correct value would cause underflow, a value whose magnitude  is
127       no  greater  than the smallest normalized positive number in the return
128       type shall be returned and errno set to [ERANGE].
129

ERRORS

131       The wcstod() function shall fail if:
132
133       ERANGE The value to be returned would cause overflow or underflow.
134
135
136       The wcstod() function may fail if:
137
138       EINVAL No conversion could be performed.
139
140
141       The following sections are informative.
142

EXAMPLES

144       None.
145

APPLICATION USAGE

147       If the subject sequence has the hexadecimal form and FLT_RADIX is not a
148       power  of  2,  and  the result is not exactly representable, the result
149       should be one of the two numbers in  the  appropriate  internal  format
150       that  are  adjacent  to the hexadecimal floating source value, with the
151       extra stipulation that the error should have a  correct  sign  for  the
152       current rounding direction.
153
154       If  the  subject  sequence has the decimal form and at most DECIMAL_DIG
155       (defined in <float.h>) significant digits, the result  should  be  cor‐
156       rectly rounded. If the subject sequence D has the decimal form and more
157       than DECIMAL_DIG significant digits, consider the two  bounding,  adja‐
158       cent  decimal strings L and U, both having DECIMAL_DIG significant dig‐
159       its, such that the values of L, D, and U satisfy "L <= D <=  U"  .  The
160       result  should  be  one of the (equal or adjacent) values that would be
161       obtained by correctly rounding L and U according to the current  round‐
162       ing  direction,  with the extra stipulation that the error with respect
163       to D should have a correct sign for the current rounding direction.
164

RATIONALE

166       None.
167

FUTURE DIRECTIONS

169       None.
170

SEE ALSO

172       iswspace(), localeconv(), scanf(), setlocale(), wcstol(), the Base Def‐
173       initions  volume of IEEE Std 1003.1-2001, Chapter 7, Locale, <float.h>,
174       <wchar.h>
175
177       Portions of this text are reprinted and reproduced in  electronic  form
178       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
179       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
180       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
181       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
182       event of any discrepancy between this version and the original IEEE and
183       The Open Group Standard, the original IEEE and The Open Group  Standard
184       is  the  referee document. The original Standard can be obtained online
185       at http://www.opengroup.org/unix/online.html .
186
187
188
189IEEE/The Open Group                  2003                           WCSTOD(3P)
Impressum