1 WCSTOD(3C) Standard C Library Functions WCSTOD(3C) 2 3 4 5 NAME 6 wcstod, wcstof, wcstold, wstod, watof - convert wide character string 7 to floating-point number 8 9 SYNOPSIS 10 #include <wchar.h> 11 12 double wcstod(const wchar_t *restrict nptr, 13 wchar_t **restrict endptr); 14 15 16 float wcstof(const wchar_t *restrict nptr, 17 wchar_t **restrict endptr); 18 19 20 long double wcstold(const wchar_t *restrict nptr, 21 wchar_t **restrict endptr); 22 23 24 double wstod(const wchar_t *nptr, wchar_t **endptr); 25 26 27 double watof(wchar_t *nptr); 28 29 30 DESCRIPTION 31 The wcstod(), wcstof(), and wcstold() functions convert the initial 32 portion of the wide-character string pointed to by nptr to double, 33 float, and long double representation, respectively. They first 34 decompose the input wide-character string into three parts: 35 36 1. An initial, possibly empty, sequence of white-space wide- 37 character codes (as specified by iswspace(3C)) 38 39 2. A subject sequence interpreted as a floating-point constant 40 or representing infinity or NaN 41 42 3. A final wide-character string of one or more unrecognized 43 wide-character codes, including the terminating null wide- 44 character code of the input wide-character string. 45 46 47 Then they attempt to convert the subject sequence to a floating-point 48 number, and return the result. 49 50 51 The expected form of the subject sequence is an optional plus or minus 52 sign, then one of the following: 53 54 o A non-empty sequence of decimal digits optionally containing 55 a radix character, then an optional exponent part 56 57 o A 0x or 0X, then a non-empty sequence of hexadecimal digits 58 optionally containing a radix character, then an optional 59 binary exponent part 60 61 o One of INF or INFINITY, or any other wide string equivalent 62 except for case 63 64 o One of NAN or NAN(n-wchar-sequence(opt)), or any other wide 65 string ignoring case in the NAN part, where: 66 67 n-wchar-sequence: 68 digit 69 nondigit 70 n-wchar-sequence digit 71 n-wchar-sequence nondigit 72 73 74 75 In default mode for wcstod(), only decimal, INF/INFINITY, and 76 NAN/NAN(n-wchar-sequence) forms are recognized. In C99/SUSv3 mode, 77 hexadecimal strings are also recognized. 78 79 80 In default mode for wcstod(), the n-wchar-sequence in the NAN(n-wchar- 81 sequence) form can contain any character except ')' (right parenthesis) 82 or '\0' (null). In C99/SUSv3 mode, the n-wchar-sequence can contain 83 only upper and lower case letters, digits, and '_' (underscore). 84 85 86 The wcstof() and wcstold() functions always function in 87 C99/SUSv3-conformant mode. 88 89 90 The subject sequence is defined as the longest initial subsequence of 91 the input wide string, starting with the first non-white-space wide 92 character, that is of the expected form. The subject sequence contains 93 no wide characters if the input wide string is not of the expected 94 form. 95 96 97 If the subject sequence has the expected form for a floating-point 98 number, the sequence of wide characters starting with the first digit 99 or the radix character (whichever occurs first) is interpreted as a 100 floating constant according to the rules of the C language, except that 101 the radix character is used in place of a period, and that if neither 102 an exponent part nor a radix character appears in a decimal floating- 103 point number, or if a binary exponent part does not appear in a 104 hexadecimal floating-point number, an exponent part of the appropriate 105 type with value zero is assumed to follow the last digit in the string. 106 If the subject sequence begins with a minus sign, the sequence is 107 interpreted as negated. A wide-character sequence INF or INFINITY is 108 interpreted as an infinity. A wide-character sequence NAN or NAN(n- 109 wchar-sequence(opt)) is interpreted as a quiet NaN. A pointer to the 110 final wide string is stored in the object pointed to by endptr, 111 provided that endptr is not a null pointer. 112 113 114 If the subject sequence has either the decimal or hexadecimal form, the 115 value resulting from the conversion is rounded correctly according to 116 the prevailing floating point rounding direction mode. The conversion 117 also raises floating point inexact, underflow, or overflow exceptions 118 as appropriate. 119 120 121 The radix character is defined in the program's locale (category 122 LC_NUMERIC). In the POSIX locale, or in a locale where the radix 123 character is not defined, the radix character defaults to a period 124 ('.'). 125 126 127 If the subject sequence is empty or does not have the expected form, no 128 conversion is performed; the value of nptr is stored in the object 129 pointed to by endptr, provided that endptr is not a null pointer. 130 131 132 The wcstod() function does not change the setting of errno if 133 successful. 134 135 136 The wstod() function is identical to wcstod(). 137 138 139 The watof(str) function is equivalent to wstod(nptr, (wchar_t **)NULL). 140 141 RETURN VALUES 142 Upon successful completion, these functions return the converted value. 143 If no conversion could be performed, 0 is returned. 144 145 146 If the correct value is outside the range of representable values, 147 +-HUGE_VAL, +-HUGE_VALF, or +-HUGE_VALL is returned (according to the 148 sign of the value), a floating point overflow exception is raised, and 149 errno is set to ERANGE. 150 151 152 If the correct value would cause an underflow, the correctly rounded 153 result (which may be normal, subnormal, or zero) is returned, a 154 floating point underflow exception is raised, and errno is set to 155 ERANGE. 156 157 ERRORS 158 The wcstod() and wstod() functions will fail if: 159 160 ERANGE 161 The value to be returned would cause overflow or underflow. 162 163 164 165 The wcstod() and wcstod() functions may fail if: 166 167 EINVAL 168 No conversion could be performed. 169 170 171 USAGE 172 Because 0 is returned on error and is also a valid return on success, 173 an application wishing to check for error situations should set errno 174 to 0 call wcstod(), wcstof(), wcstold(), or wstod(), then check errno 175 and if it is non-zero, assume an error has occurred. 176 177 ATTRIBUTES 178 See attributes(5) for descriptions of the following attributes: 179 180 181 182 183 +--------------------+-------------------------+ 184 |ATTRIBUTE TYPE | ATTRIBUTE VALUE | 185 +--------------------+-------------------------+ 186 |Interface Stability | wcstod(), wcstof(), and | 187 | | wcstold() are Standard. | 188 +--------------------+-------------------------+ 189 |MT-Level | MT-Safe | 190 +--------------------+-------------------------+ 191 192 SEE ALSO 193 iswspace(3C), localeconv(3C), scanf(3C), setlocale(3C), wcstol(3C), 194 attributes(5), standards(5) 195 196 197 198 August 25, 2019 WCSTOD(3C)