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 "Mar 31, 2003" 47 .SH NAME 48 wcstod, wcstof, wcstold, wstod, watof \- convert wide character string to 49 floating-point number 50 .SH SYNOPSIS 51 .LP 52 .nf 53 #include <wchar.h> 54 55 \fBdouble\fR \fBwcstod\fR(\fBconst wchar_t *restrict\fR \fInptr\fR, 56 \fBwchar_t **restrict\fR \fIendptr\fR); 57 .fi 58 59 .LP 60 .nf 61 \fBfloat\fR \fBwcstof\fR(\fBconst wchar_t *restrict\fR \fInptr\fR, 62 \fBwchar_t **restrict\fR \fIendptr\fR); 63 .fi 64 65 .LP 66 .nf 67 \fBlong double\fR \fBwcstold\fR(\fBconst wchar_t *restrict\fR \fInptr\fR, 68 \fBwchar_t **restrict\fR \fIendptr\fR); 69 .fi 70 71 .LP 72 .nf 73 \fBdouble\fR \fBwstod\fR(\fBconst wchar_t *\fR\fInptr\fR, \fBwchar_t **\fR\fIendptr\fR); 74 .fi 75 76 .LP 77 .nf 78 \fBdouble\fR \fBwatof\fR(\fBwchar_t *\fR\fInptr\fR); 79 .fi 80 81 .SH DESCRIPTION 82 .sp 83 .LP 84 The \fBwcstod()\fR, \fBwcstof()\fR, and \fBwcstold()\fR functions convert the 85 initial portion of the wide-character string pointed to by \fInptr\fR to 86 \fBdouble\fR, \fBfloat\fR, and \fBlong double\fR representation, respectively. 87 They first decompose the input wide-character string into three parts: 88 .RS +4 89 .TP 90 1. 91 An initial, possibly empty, sequence of white-space wide-character codes (as 92 specified by \fBiswspace\fR(3C)) 93 .RE 94 .RS +4 95 .TP 96 2. 97 A subject sequence interpreted as a floating-point constant or representing 98 infinity or NaN 99 .RE 100 .RS +4 101 .TP 102 3. 103 A final wide-character string of one or more unrecognized wide-character 104 codes, including the terminating null wide-character code of the input 105 wide-character string. 106 .RE 107 .sp 108 .LP 109 Then they attempt to convert the subject sequence to a floating-point number, 110 and return the result. 111 .sp 112 .LP 113 The expected form of the subject sequence is an optional plus or minus sign, 114 then one of the following: 115 .RS +4 116 .TP 117 .ie t \(bu 118 .el o 119 A non-empty sequence of decimal digits optionally containing a radix character, 120 then an optional exponent part 121 .RE 122 .RS +4 123 .TP 124 .ie t \(bu 125 .el o 126 A 0x or 0X, then a non-empty sequence of hexadecimal digits optionally 127 containing a radix character, then an optional binary exponent part 128 .RE 129 .RS +4 130 .TP 131 .ie t \(bu 132 .el o 133 One of INF or INFINITY, or any other wide string equivalent except for case 134 .RE 135 .RS +4 136 .TP 137 .ie t \(bu 138 .el o 139 One of NAN or NAN(\fIn-wchar-sequence\fR(\fIopt\fR)), or any other wide string 140 ignoring case in the NAN part, where: 141 .sp 142 .in +2 143 .nf 144 n-wchar-sequence: 145 digit 146 nondigit 147 n-wchar-sequence digit 148 n-wchar-sequence nondigit 149 .fi 150 .in -2 151 152 .RE 153 .sp 154 .LP 155 In default mode for \fBwcstod()\fR, only decimal, INF/INFINITY, and 156 NAN/NAN(\fIn-char-sequence\fR) forms are recognized. In C99/SUSv3 mode, 157 hexadecimal strings are also recognized. 158 .sp 159 .LP 160 In default mode for \fBwcstod()\fR, the \fIn-char-sequence\fR in the 161 NAN(\fIn-char-equence\fR) form can contain any character except ')' (right 162 parenthesis) or '\e0' (null). In C99/SUSv3 mode, the \fIn-char-sequence\fR can 163 contain only upper and lower case letters, digits, and '_' (underscore). 164 .sp 165 .LP 166 The \fBwcstof()\fR and \fBwcstold()\fR functions always function in 167 C99/SUSv3-conformant mode. 168 .sp 169 .LP 170 The subject sequence is defined as the longest initial subsequence of the input 171 wide string, starting with the first non-white-space wide character, that is of 172 the expected form. The subject sequence contains no wide characters if the 173 input wide string is not of the expected form. 174 .sp 175 .LP 176 If the subject sequence has the expected form for a floating-point number, the 177 sequence of wide characters starting with the first digit or the radix 178 character (whichever occurs first) is interpreted as a floating constant 179 according to the rules of the C language, except that the radix character is 180 used in place of a period, and that if neither an exponent part nor a radix 181 character appears in a decimal floating-point number, or if a binary exponent 182 part does not appear in a hexadecimal floating-point number, an exponent part 183 of the appropriate type with value zero is assumed to follow the last digit in 184 the string. If the subject sequence begins with a minus sign, the sequence is 185 interpreted as negated. A wide-character sequence INF or INFINITY is 186 interpreted as an infinity. A wide-character sequence NAN or 187 NAN(\fIn-wchar-sequence\fR(\fIopt\fR)) is interpreted as a quiet NaN. A pointer 188 to the final wide string is stored in the object pointed to by \fIendptr\fR, 189 provided that \fIendptr\fR is not a null pointer. 190 .sp 191 .LP 192 If the subject sequence has either the decimal or hexadecimal form, the value 193 resulting from the conversion is rounded correctly according to the prevailing 194 floating point rounding direction mode. The conversion also raises floating 195 point inexact, underflow, or overflow exceptions as appropriate. 196 .sp 197 .LP 198 The radix character is defined in the program's locale (category 199 \fBLC_NUMERIC\fR). In the POSIX locale, or in a locale where the radix 200 character is not defined, the radix character defaults to a period ('.'). 201 .sp 202 .LP 203 If the subject sequence is empty or does not have the expected form, no 204 conversion is performed; the value of \fInptr\fR is stored in the object 205 pointed to by \fIendptr\fR, provided that \fIendptr\fR is not a null pointer. 206 .sp 207 .LP 208 The \fBwcstod()\fR function does not change the setting of \fBerrno\fR if 209 successful. 210 .sp 211 .LP 212 The \fBwstod()\fR function is identical to \fBwcstod()\fR. 213 .sp 214 .LP 215 The \fBwatof\fR(\fIstr\fR) function is equivalent to \fBwstod(\fR\fInptr\fR\fB, 216 (wchar_t **)NULL)\fR. 217 .SH RETURN VALUES 218 .sp 219 .LP 220 Upon successful completion, these functions return the converted value. If no 221 conversion could be performed, \fB0\fR is returned. 222 .sp 223 .LP 224 If the correct value is outside the range of representable values, 225 \fB\(+-HUGE_VAL\fR, \fB\(+-HUGE_VALF\fR, or \fB\(+-HUGE_VALL\fR is returned 226 (according to the sign of the value), a floating point overflow exception is 227 raised, and \fBerrno\fR is set to \fBERANGE\fR. 228 .sp 229 .LP 230 If the correct value would cause an underflow, the correctly rounded result 231 (which may be normal, subnormal, or zero) is returned, a floating point 232 underflow exception is raised, and \fBerrno\fR is set to \fBERANGE\fR. 233 .SH ERRORS 234 .sp 235 .LP 236 The \fBwcstod()\fR and \fBwstod()\fR functions will fail if: 237 .sp 238 .ne 2 239 .na 240 \fB\fBERANGE\fR\fR 241 .ad 242 .RS 10n 243 The value to be returned would cause overflow or underflow. 244 .RE 245 246 .sp 247 .LP 248 The \fBwcstod()\fR and \fBwcstod()\fR functions may fail if: 249 .sp 250 .ne 2 251 .na 252 \fB\fBEINVAL\fR\fR 253 .ad 254 .RS 10n 255 No conversion could be performed. 256 .RE 257 258 .SH USAGE 259 .sp 260 .LP 261 Because 0 is returned on error and is also a valid return on success, an 262 application wishing to check for error situations should set \fBerrno\fR to 0 263 call \fBwcstod()\fR, \fBwcstof()\fR, \fBwcstold()\fR, or \fBwstod()\fR, then 264 check \fBerrno\fR and if it is non-zero, assume an error has occurred. 265 .SH ATTRIBUTES 266 .sp 267 .LP 268 See \fBattributes\fR(5) for descriptions of the following attributes: 269 .sp 270 271 .sp 272 .TS 273 box; 274 l | l 275 l | l . 276 ATTRIBUTE TYPE ATTRIBUTE VALUE 277 _ 278 Interface Stability T{ 279 \fBwcstod()\fR, \fBwcstof()\fR, and \fBwcstold()\fR are Standard. 280 T} 281 _ 282 MT-Level MT-Safe 283 .TE 284 285 .SH SEE ALSO 286 .sp 287 .LP 288 \fBiswspace\fR(3C), \fBlocaleconv\fR(3C), \fBscanf\fR(3C), \fBsetlocale\fR(3C), 289 \fBwcstol\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)