1 .\"
   2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
   3 .\" permission to reproduce portions of its copyrighted documentation.
   4 .\" Original documentation from The Open Group can be obtained online at
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\"
   7 .\" The Institute of Electrical and Electronics Engineers and The Open
   8 .\" Group, have given us permission to reprint portions of their
   9 .\" documentation.
  10 .\"
  11 .\" In the following statement, the phrase ``this text'' refers to portions
  12 .\" of the system documentation.
  13 .\"
  14 .\" Portions of this text are reprinted and reproduced in electronic form
  15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
  16 .\" Standard for Information Technology -- Portable Operating System
  17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
  18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
  19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
  20 .\" between these versions and the original IEEE and The Open Group
  21 .\" Standard, the original IEEE and The Open Group Standard is the referee
  22 .\" document.  The original Standard can be obtained online at
  23 .\" http://www.opengroup.org/unix/online.html.
  24 .\"
  25 .\" This notice shall appear on any product containing this material.
  26 .\"
  27 .\" The contents of this file are subject to the terms of the
  28 .\" Common Development and Distribution License (the "License").
  29 .\" You may not use this file except in compliance with the License.
  30 .\"
  31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  32 .\" or http://www.opensolaris.org/os/licensing.
  33 .\" See the License for the specific language governing permissions
  34 .\" and limitations under the License.
  35 .\"
  36 .\" When distributing Covered Code, include this CDDL HEADER in each
  37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  38 .\" If applicable, add the following below this CDDL HEADER, with the
  39 .\" fields enclosed by brackets "[]" replaced with your own identifying
  40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  41 .\"
  42 .\"
  43 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
  44 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved
  45 .\"
  46 .TH WCSTOD 3C "Aug 25, 2019"
  47 .SH NAME
  48 wcstod, wcstof, wcstold, wstod, watof \- convert wide character string to
  49 floating-point number
  50 .SH SYNOPSIS
  51 .nf
  52 #include <wchar.h>
  53 
  54 \fBdouble\fR \fBwcstod\fR(\fBconst wchar_t *restrict\fR \fInptr\fR,
  55      \fBwchar_t **restrict\fR \fIendptr\fR);
  56 .fi
  57 
  58 .LP
  59 .nf
  60 \fBfloat\fR \fBwcstof\fR(\fBconst wchar_t *restrict\fR \fInptr\fR,
  61      \fBwchar_t **restrict\fR \fIendptr\fR);
  62 .fi
  63 
  64 .LP
  65 .nf
  66 \fBlong double\fR \fBwcstold\fR(\fBconst wchar_t *restrict\fR \fInptr\fR,
  67      \fBwchar_t **restrict\fR \fIendptr\fR);
  68 .fi
  69 
  70 .LP
  71 .nf
  72 \fBdouble\fR \fBwstod\fR(\fBconst wchar_t *\fR\fInptr\fR, \fBwchar_t **\fR\fIendptr\fR);
  73 .fi
  74 
  75 .LP
  76 .nf
  77 \fBdouble\fR \fBwatof\fR(\fBwchar_t *\fR\fInptr\fR);
  78 .fi
  79 
  80 .SH DESCRIPTION
  81 The \fBwcstod()\fR, \fBwcstof()\fR, and \fBwcstold()\fR functions convert the
  82 initial portion of the wide-character string pointed to by \fInptr\fR to
  83 \fBdouble\fR, \fBfloat\fR, and \fBlong double\fR representation, respectively.
  84 They first decompose the input wide-character string into three parts:
  85 .RS +4
  86 .TP
  87 1.
  88 An initial, possibly empty, sequence of white-space wide-character codes (as
  89 specified by \fBiswspace\fR(3C))
  90 .RE
  91 .RS +4
  92 .TP
  93 2.
  94 A subject sequence interpreted as a floating-point constant or representing
  95 infinity or NaN
  96 .RE
  97 .RS +4
  98 .TP
  99 3.
 100 A final wide-character string of one or more unrecognized wide-character
 101 codes, including the terminating null wide-character code of the input
 102 wide-character string.
 103 .RE
 104 .sp
 105 .LP
 106 Then they attempt to convert the subject sequence to a floating-point number,
 107 and return the result.
 108 .sp
 109 .LP
 110 The expected form of the subject sequence is an optional plus or minus sign,
 111 then one of the following:
 112 .RS +4
 113 .TP
 114 .ie t \(bu
 115 .el o
 116 A non-empty sequence of decimal digits optionally containing a radix character,
 117 then an optional exponent part
 118 .RE
 119 .RS +4
 120 .TP
 121 .ie t \(bu
 122 .el o
 123 A 0x or 0X, then a non-empty sequence of hexadecimal digits optionally
 124 containing a radix character, then an optional binary exponent part
 125 .RE
 126 .RS +4
 127 .TP
 128 .ie t \(bu
 129 .el o
 130 One of INF or INFINITY, or any other wide string equivalent except for case
 131 .RE
 132 .RS +4
 133 .TP
 134 .ie t \(bu
 135 .el o
 136 One of NAN or NAN(\fIn-wchar-sequence\fR(\fIopt\fR)), or any other wide string
 137 ignoring case in the NAN part, where:
 138 .sp
 139 .in +2
 140 .nf
 141 n-wchar-sequence:
 142     digit
 143     nondigit
 144     n-wchar-sequence digit
 145     n-wchar-sequence nondigit
 146 .fi
 147 .in -2
 148 
 149 .RE
 150 .sp
 151 .LP
 152 In default mode for \fBwcstod()\fR, only decimal, INF/INFINITY, and
 153 NAN/NAN(\fIn-wchar-sequence\fR) forms are recognized. In C99/SUSv3 mode,
 154 hexadecimal strings are also recognized.
 155 .sp
 156 .LP
 157 In default mode for \fBwcstod()\fR, the \fIn-wchar-sequence\fR in the
 158 NAN(\fIn-wchar-sequence\fR) form can contain any character except ')' (right
 159 parenthesis) or '\e0' (null).  In C99/SUSv3 mode, the \fIn-wchar-sequence\fR can
 160 contain only upper and lower case letters, digits, and '_' (underscore).
 161 .sp
 162 .LP
 163 The \fBwcstof()\fR and \fBwcstold()\fR functions always function in
 164 C99/SUSv3-conformant mode.
 165 .sp
 166 .LP
 167 The subject sequence is defined as the longest initial subsequence of the input
 168 wide string, starting with the first non-white-space wide character, that is of
 169 the expected form. The subject sequence contains no wide characters if the
 170 input wide string is not of the expected form.
 171 .sp
 172 .LP
 173 If the subject sequence has the expected form for a floating-point number, the
 174 sequence of wide characters starting with the first digit or the radix
 175 character (whichever occurs first) is interpreted as a floating constant
 176 according to the rules of the C language, except that the radix character is
 177 used in place of a period, and that if neither an exponent part nor a radix
 178 character appears in a decimal floating-point number, or if a binary exponent
 179 part does not appear in a hexadecimal floating-point number, an exponent part
 180 of the appropriate type with value zero is assumed to follow the last digit in
 181 the string. If the subject sequence begins with a minus sign, the sequence is
 182 interpreted as negated. A wide-character sequence INF or INFINITY is
 183 interpreted as an infinity. A wide-character sequence NAN or
 184 NAN(\fIn-wchar-sequence\fR(\fIopt\fR)) is interpreted as a quiet NaN. A pointer
 185 to the final wide string is stored in the object pointed to by \fIendptr\fR,
 186 provided that \fIendptr\fR is not a null pointer.
 187 .sp
 188 .LP
 189 If the subject sequence has either the decimal or hexadecimal form, the value
 190 resulting from the conversion is rounded correctly according to the prevailing
 191 floating point rounding direction mode. The conversion also raises floating
 192 point inexact, underflow, or overflow exceptions as appropriate.
 193 .sp
 194 .LP
 195 The radix character is defined in the program's locale (category
 196 \fBLC_NUMERIC\fR). In the POSIX locale, or in a locale where the radix
 197 character is not defined, the radix character defaults to a period ('.').
 198 .sp
 199 .LP
 200 If the subject sequence is empty or does not have the expected form, no
 201 conversion is performed; the value of  \fInptr\fR is stored in the object
 202 pointed to by \fIendptr\fR, provided that  \fIendptr\fR is not a null pointer.
 203 .sp
 204 .LP
 205 The \fBwcstod()\fR function does not change the setting of \fBerrno\fR if
 206 successful.
 207 .sp
 208 .LP
 209 The \fBwstod()\fR function is identical to \fBwcstod()\fR.
 210 .sp
 211 .LP
 212 The \fBwatof\fR(\fIstr\fR) function is equivalent to \fBwstod(\fR\fInptr\fR\fB,
 213 (wchar_t **)NULL)\fR.
 214 .SH RETURN VALUES
 215 Upon successful completion, these functions return the converted value. If no
 216 conversion could be performed, \fB0\fR is returned.
 217 .sp
 218 .LP
 219 If the correct value is outside the range of representable values,
 220 \fB\(+-HUGE_VAL\fR, \fB\(+-HUGE_VALF\fR, or \fB\(+-HUGE_VALL\fR is returned
 221 (according to the sign of the value), a floating point overflow exception is
 222 raised, and \fBerrno\fR is set to \fBERANGE\fR.
 223 .sp
 224 .LP
 225 If the correct value would cause an underflow, the correctly rounded result
 226 (which may be normal, subnormal, or zero) is returned, a floating point
 227 underflow exception is raised, and \fBerrno\fR is set to \fBERANGE\fR.
 228 .SH ERRORS
 229 The \fBwcstod()\fR and \fBwstod()\fR functions will fail if:
 230 .sp
 231 .ne 2
 232 .na
 233 \fBERANGE\fR
 234 .ad
 235 .RS 10n
 236 The value to be returned would cause overflow or underflow.
 237 .RE
 238 
 239 .sp
 240 .LP
 241 The \fBwcstod()\fR and \fBwcstod()\fR functions may fail if:
 242 .sp
 243 .ne 2
 244 .na
 245 \fBEINVAL\fR
 246 .ad
 247 .RS 10n
 248 No conversion could be performed.
 249 .RE
 250 
 251 .SH USAGE
 252 Because 0 is returned on error and is also a valid return on success, an
 253 application wishing to check for error situations should set \fBerrno\fR to 0
 254 call \fBwcstod()\fR, \fBwcstof()\fR, \fBwcstold()\fR, or \fBwstod()\fR, then
 255 check  \fBerrno\fR and if it is non-zero, assume an error has occurred.
 256 .SH ATTRIBUTES
 257 See \fBattributes\fR(5) for descriptions of the following attributes:
 258 .sp
 259 
 260 .sp
 261 .TS
 262 box;
 263 l | l
 264 l | l .
 265 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 266 _
 267 Interface Stability     T{
 268 \fBwcstod()\fR, \fBwcstof()\fR, and \fBwcstold()\fR are Standard.
 269 T}
 270 _
 271 MT-Level        MT-Safe
 272 .TE
 273 
 274 .SH SEE ALSO
 275 \fBiswspace\fR(3C), \fBlocaleconv\fR(3C), \fBscanf\fR(3C), \fBsetlocale\fR(3C),
 276 \fBwcstol\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)