📄 wcstof.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>wcstod</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="wcstod"></a> <a name="tag_03_842"></a><!-- wcstod --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_842_01"></a>NAME</h4><blockquote>wcstod, wcstof, wcstold - convert a wide-character string to a double-precision number</blockquote><h4><a name="tag_03_842_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/wchar.h.html">wchar.h</a>><br><br> double wcstod(const wchar_t *restrict</tt> <i>nptr</i><tt>, wchar_t **restrict</tt> <i>endptr</i><tt>);<br> float wcstof(const wchar_t *restrict</tt> <i>nptr</i><tt>, wchar_t **restrict</tt> <i>endptr</i><tt>);<br> long double wcstold(const wchar_t *restrict</tt> <i>nptr</i><tt>,<br> wchar_t **restrict</tt> <i>endptr</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_842_03"></a>DESCRIPTION</h4><blockquote><div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> The functionality described on this reference page is aligned with the ISO C standard. Any conflict between therequirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers tothe ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div><p>These functions shall convert the initial portion of the wide-character string pointed to by <i>nptr</i> to <b>double</b>,<b>float</b>, and <b>long double</b> representation, respectively. First, they shall decompose the input wide-character string intothree parts:</p><ol><li><p>An initial, possibly empty, sequence of white-space wide-character codes (as specified by <a href="../functions/iswspace.html"><i>iswspace</i>()</a>)</p></li><li><p>A subject sequence interpreted as a floating-point constant or representing infinity or NaN</p></li><li><p>A final wide-character string of one or more unrecognized wide-character codes, including the terminating null wide-charactercode of the input wide-character string</p></li></ol><p>Then they shall attempt to convert the subject sequence to a floating-point number, and return the result.</p><p>The expected form of the subject sequence is an optional plus or minus sign, then one of the following:</p><ul><li><p>A non-empty sequence of decimal digits optionally containing a radix character, then an optional exponent part</p></li><li><p>A 0x or 0X, then a non-empty sequence of hexadecimal digits optionally containing a radix character, then an optional binaryexponent part</p></li><li><p>One of INF or INFINITY, or any other wide string equivalent except for case</p></li><li><p>One of NAN or NAN(<i>n-wchar-sequence<small><sub>opt</sub></small></i>), or any other wide string ignoring case in the NAN part,where:</p><pre><tt>n-wchar-sequence: digit nondigit n-wchar-sequence digit n-wchar-sequence nondigit</tt></pre></li></ul><p>The subject sequence is defined as the longest initial subsequence of the input wide string, starting with the firstnon-white-space wide character, that is of the expected form. The subject sequence contains no wide characters if the input widestring is not of the expected form.</p><p>If the subject sequence has the expected form for a floating-point number, the sequence of wide characters starting with thefirst digit or the radix character (whichever occurs first) shall be interpreted as a floating constant according to the rules ofthe C language, except that the radix character shall be used in place of a period, and that if neither an exponent part nor aradix character appears in a decimal floating-point number, or if a binary exponent part does not appear in a hexadecimalfloating-point number, an exponent part of the appropriate type with value zero shall be assumed to follow the last digit in thestring. If the subject sequence begins with a minus sign, the sequence shall be interpreted as negated. A wide-character sequenceINF or INFINITY shall be interpreted as an infinity, if representable in the return type, else as if it were a floating constantthat is too large for the range of the return type. A wide-character sequence NAN orNAN(<i>n-wchar-sequence<small><sub>opt</sub></small></i>) shall be interpreted as a quiet NaN, if supported in the return type,else as if it were a subject sequence part that does not have the expected form; the meaning of the <i>n</i>-wchar sequences isimplementation-defined. A pointer to the final wide string shall be stored in the object pointed to by <i>endptr</i>, provided that<i>endptr</i> is not a null pointer.</p><p>If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the conversion shall be rounded in animplementation-defined manner.</p><p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Theradix character shall be as defined in the program's locale (category <i>LC_NUMERIC ).</i> In the POSIX locale, or in a localewhere the radix character is not defined, the radix character shall default to a period ( <tt>'.'</tt> ). <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>In other than the C <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or POSIX <img src="../images/opt-end.gif" alt="[Option End]" border="0"> locales, otherimplementation-defined subject sequences may be accepted.</p><p>If the subject sequence is empty or does not have the expected form, no conversion shall be performed; the value of <i>nptr</i>shall be stored in the object pointed to by <i>endptr</i>, provided that <i>endptr</i> is not a null pointer.</p><p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> The<i>wcstod</i>() function shall not change the setting of <i>errno</i> if successful.</p><p>Since 0 is returned on error and is also a valid return on success, an application wishing to check for error situations shouldset <i>errno</i> to 0, then call <i>wcstod</i>(), <i>wcstof</i>(), or <i>wcstold</i>(), then check <i>errno</i>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_842_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, these functions shall return the converted value. If no conversion could be performed, 0 shall bereturned <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and <i>errno</i> may be set to [EINVAL]. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>If the correct value is outside the range of representable values, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALLshall be returned (according to the sign of the value), and <i>errno</i> shall be set to [ERANGE].</p><p>If the correct value would cause underflow, a value whose magnitude is no greater than the smallest normalized positive numberin the return type shall be returned and <i>errno</i> set to [ERANGE].</p></blockquote><h4><a name="tag_03_842_05"></a>ERRORS</h4><blockquote><p>The <i>wcstod</i>() function shall fail if:</p><dl compact><dt>[ERANGE]</dt><dd>The value to be returned would cause overflow or underflow.</dd></dl><p>The <i>wcstod</i>() function may fail if:</p><dl compact><dt>[EINVAL]</dt><dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Noconversion could be performed. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_842_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_842_07"></a>APPLICATION USAGE</h4><blockquote><p>If the subject sequence has the hexadecimal form and FLT_RADIX is not a power of 2, and the result is not exactly representable,the result should be one of the two numbers in the appropriate internal format that are adjacent to the hexadecimal floating sourcevalue, with the extra stipulation that the error should have a correct sign for the current rounding direction.</p><p>If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in <a href="../basedefs/float.h.html"><i><float.h></i></a>) significant digits, the result should be correctly rounded. If the subjectsequence <i>D</i> has the decimal form and more than DECIMAL_DIG significant digits, consider the two bounding, adjacent decimalstrings <i>L</i> and <i>U</i>, both having DECIMAL_DIG significant digits, such that the values of <i>L</i>, <i>D</i>, and <i>U</i>satisfy <tt>"L <= D <= U"</tt> . The result should be one of the (equal or adjacent) values that would be obtained bycorrectly rounding <i>L</i> and <i>U</i> according to the current rounding direction, with the extra stipulation that the errorwith respect to <i>D</i> should have a correct sign for the current rounding direction.</p></blockquote><h4><a name="tag_03_842_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_842_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_842_10"></a>SEE ALSO</h4><blockquote><p><a href="iswspace.html"><i>iswspace</i>()</a> , <a href="localeconv.html"><i>localeconv</i>()</a> , <a href="scanf.html"><i>scanf</i>()</a> , <a href="setlocale.html"><i>setlocale</i>()</a> , <a href="wcstol.html"><i>wcstol</i>()</a> , theBase Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap07.html">Chapter 7, Locale</a>, <a href="../basedefs/float.h.html"><i><float.h></i></a>, <a href="../basedefs/wchar.h.html"><i><wchar.h></i></a></p></blockquote><h4><a name="tag_03_842_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4. Derived from the MSE working draft.</p></blockquote><h4><a name="tag_03_842_12"></a>Issue 5</h4><blockquote><p>The DESCRIPTION is updated to indicate that <i>errno</i> is not changed if the function is successful.</p></blockquote><h4><a name="tag_03_842_13"></a>Issue 6</h4><blockquote><p>Extensions beyond the ISO C standard are marked.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>In the RETURN VALUE and ERRORS sections, the [EINVAL] optional error condition is added if no conversion could be performed.</p></li></ul><p>The following changes are made for alignment with the ISO/IEC 9899:1999 standard:</p><ul><li><p>The <i>wcstod</i>() prototype is updated.</p></li><li><p>The <i>wcstof</i>() and <i>wcstold</i>() functions are added.</p></li><li><p>If the correct value for <i>wcstod</i>() would cause underflow, the return value changed from 0 (as specified in Issue 5) to thesmallest normalized positive number.</p></li><li><p>The DESCRIPTION, RETURN VALUE, and APPLICATION USAGE sections are extensively updated.</p></li></ul><p>ISO/IEC 9899:1999 standard, Technical Corrigendum No. 1 is incorporated.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XSH/TC1/D6/66 is applied, correcting the second paragraph in the RETURN VALUEsection.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -