summaryrefslogtreecommitdiff
path: root/devdocs/c/string%2Fwide%2Fwcstof.html
blob: 30bf2d8217e4adcdbf13a43233a8acf3f2c46a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    <h1 id="firstHeading" class="firstHeading">wcstof, wcstod, wcstold</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;wchar.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float       wcstof( const wchar_t * restrict str, wchar_t ** restrict str_end );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr>   <tr class="t-dcl t-since-c95 t-until-c99"> <td><pre data-language="c">double      wcstod( const wchar_t * str, wchar_t ** str_end );</pre></td> <td class="t-dcl-nopad"> </td> <td>
<span class="t-mark-rev t-since-c95">(since C95)</span> <br><span class="t-mark-rev t-until-c99">(until C99)</span>
</td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">double      wcstod( const wchar_t * restrict str, wchar_t ** restrict str_end );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr>  <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long double wcstold( const wchar_t * restrict str, wchar_t ** restrict str_end );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr>  </table> <p>Interprets a floating point value in a wide string pointed to by <code>str</code>.</p>
<p>Function discards any whitespace characters (as determined by <code><a href="iswspace" title="c/string/wide/iswspace">iswspace</a></code>) until first non-whitespace character is found. Then it takes as many characters as possible to form a valid floating-point representation and converts them to a floating-point value. The valid floating-point value can be one of the following:</p>
<ul>
<li>decimal floating-point expression. It consists of the following parts: </li>
<ul>
<li> <span class="t-mark">(optional)</span> plus or minus sign </li>
<li> nonempty sequence of decimal digits optionally containing decimal-point character (as determined by the current C <a href="../../locale/setlocale" title="c/locale/setlocale">locale</a>) (defines significand) </li>
<li> <span class="t-mark">(optional)</span> <code>e</code> or <code>E</code> followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent to base 10) </li>
</ul>
</ul>  <table class="t-rev-begin"> <tr class="t-rev t-since-c99">
<td> <ul>
<li>hexadecimal floating-point expression. It consists of the following parts: </li>
<ul>
<li> <span class="t-mark">(optional)</span> plus or minus sign </li>
<li> <code>0x</code> or <code>0X</code> </li>
<li> nonempty sequence of hexadecimal digits optionally containing a decimal-point character (as determined by the current C <a href="../../locale/setlocale" title="c/locale/setlocale">locale</a>) (defines significand) </li>
<li> <span class="t-mark">(optional)</span> <code>p</code> or <code>P</code> followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent to base 2) </li>
</ul>
<li> infinity expression. It consists of the following parts: </li>
<ul>
<li> <span class="t-mark">(optional)</span> plus or minus sign </li>
<li> <code>INF</code> or <code>INFINITY</code> ignoring case </li>
</ul>
<li> not-a-number expression. It consists of the following parts: </li>
<ul>
<li> <span class="t-mark">(optional)</span> plus or minus sign </li>
<li> <code>NAN</code> or <code>NAN(</code><i>char_sequence</i><code>)</code> ignoring case of the <code>NAN</code> part. <i>char_sequence</i> can only contain digits, Latin letters, and underscores. The result is a quiet NaN floating-point value. </li>
</ul>
</ul>      </td> <td><span class="t-mark-rev t-since-c99">(since C99)</span></td>
</tr> </table> <ul><li> any other expression that may be accepted by the currently installed C <a href="../../locale/setlocale" title="c/locale/setlocale">locale</a> </li></ul> <p>The functions sets the pointer pointed to by <code>str_end</code> to point to the wide character past the last character interpreted. If <code>str_end</code> is a null pointer, it is ignored.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> str </td> <td> - </td> <td> pointer to the null-terminated wide string to be interpreted </td>
</tr> <tr class="t-par"> <td> str_end </td> <td> - </td> <td> pointer to a pointer to a wide character. </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>Floating point value corresponding to the contents of <code>str</code> on success. If the converted value falls out of range of corresponding return type, range error occurs and <code><a href="../../numeric/math/huge_val" title="c/numeric/math/HUGE VAL">HUGE_VAL</a></code>, <code><a href="../../numeric/math/huge_val" title="c/numeric/math/HUGE VAL">HUGE_VALF</a></code> or <code><a href="../../numeric/math/huge_val" title="c/numeric/math/HUGE VAL">HUGE_VALL</a></code> is returned. If no conversion can be performed, <code>​0​</code> is returned.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;
#include &lt;wchar.h&gt;
 
int main(void)
{
    const wchar_t *p = L"111.11 -2.22 0X1.BC70A3D70A3D7P+6  1.18973e+4932zzz";
    printf("Parsing L\"%ls\":\n", p);
    wchar_t *end;
    for (double f = wcstod(p, &amp;end); p != end; f = wcstod(p, &amp;end))
    {
        printf("'%.*ls' -&gt; ", (int)(end-p), p);
        p = end;
        if (errno == ERANGE){
            printf("range error, got ");
            errno = 0;
        }
        printf("%f\n", f);
    }
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">Parsing L"111.11 -2.22 0X1.BC70A3D70A3D7P+6  1.18973e+4932zzz":
'111.11' -&gt; 111.110000
' -2.22' -&gt; -2.220000
' 0X1.BC70A3D70A3D7P+6' -&gt; 111.110000
'  1.18973e+4932' -&gt; range error, got inf</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.29.4.1.1 The wcstod, wcstof, and wcstold functions (p: 426-428) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.24.4.1.1 The wcstod, wcstof, and wcstold functions (p: 372-374) </li></ul>
</ul>      <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="../byte/strtof" title="c/string/byte/strtof"> <span class="t-lines"><span>strtof</span><span>strtod</span><span>strtold</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> converts a byte string to a floating point value <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/string/wide/wcstof" title="cpp/string/wide/wcstof">C++ documentation</a></span> for <code>wcstof, wcstod, wcstold</code> </td>
</tr> </table>           <div class="_attribution">
  <p class="_attribution-p">
    &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
    <a href="https://en.cppreference.com/w/c/string/wide/wcstof" class="_attribution-link">https://en.cppreference.com/w/c/string/wide/wcstof</a>
  </p>
</div>