summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fmath%2Froundeven.html
blob: 418b93ae0a99b622af1b1423f83d666e2ccf2821 (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
    <h1 id="firstHeading" class="firstHeading">roundeven, roundevenf, roundevenl</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;math.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">float       roundevenf( float arg );</pre>
</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">double      roundeven( double arg );</pre>
</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">long double roundevenl( long double arg );</pre>
</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;tgmath.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">#define roundeven( arg )</pre>
</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr>  </table> <div class="t-li1">
<span class="t-li">1-3)</span> Computes the nearest integer value to <code>arg</code> (in floating-point format), rounding halfway cases to nearest even integer, regardless of the current rounding mode.</div> <div class="t-li1">
<span class="t-li">4)</span> Type-generic macro: If <code>arg</code> has type <code>long double</code>, <code>roundevenl</code> is called. Otherwise, if <code>arg</code> has integer type or the type <code>double</code>, <code>roundeven</code> is called. Otherwise, <code>roundevenf</code> is called, respectively.</div>  <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating point value </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, the nearest integer value to <code>arg</code>, rounding halfway cases to nearest even integer, is returned.</p>
<h3 id="Error_handling"> Error handling</h3> <p>This function is not subject to any of the errors specified in <a href="math_errhandling" title="c/numeric/math/math errhandling"><code>math_errhandling</code></a>.</p>
<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559),</p>
<ul>
<li> <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INEXACT</a></code> is never raised </li>
<li> If <code>arg</code> is ±∞, it is returned, unmodified </li>
<li> If <code>arg</code> is ±0, it is returned, unmodified </li>
<li> If <code>arg</code> is NaN, NaN is returned </li>
</ul> <h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
int main(void)
{
    printf("roundeven(+2.4) = %+.1f\n", roundeven(2.4));
    printf("roundeven(-2.4) = %+.1f\n", roundeven(-2.4));
    printf("roundeven(+2.5) = %+.1f\n", roundeven(2.5));
    printf("roundeven(-2.5) = %+.1f\n", roundeven(-2.5));
    printf("roundeven(+2.6) = %+.1f\n", roundeven(2.6));
    printf("roundeven(-2.6) = %+.1f\n", roundeven(-2.6));
    printf("roundeven(+3.5) = %+.1f\n", roundeven(3.5));
    printf("roundeven(-3.5) = %+.1f\n", roundeven(-3.5));
    printf("roundeven(-0.0) = %+.1f\n", roundeven(-0.0));
    printf("roundeven(-Inf) = %+f\n",   roundeven(-INFINITY));
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">roundeven(+2.4) = +2.0
roundeven(-2.4) = -2.0
roundeven(+2.5) = +2.0
roundeven(-2.5) = -2.0
roundeven(+2.6) = +3.0
roundeven(-2.6) = -3.0
roundeven(+3.5) = +4.0
roundeven(-3.5) = -4.0
roundeven(-0.0) = -0.0
roundeven(-Inf) = -inf</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C23 standard (ISO/IEC 9899:2023): </li>
<ul>
<li> 7.12.9.8 The roundeven functions (p: 265-266) </li>
<li> 7.27 Type-generic math &lt;tgmath.h&gt; (p: 386-390) </li>
<li> F.10.6.8 The roundeven functions (p: 532) </li>
</ul>
</ul>     <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="rint" title="c/numeric/math/rint"> <span class="t-lines"><span>rint</span><span>rintf</span><span>rintl</span><span>lrint</span><span>lrintf</span><span>lrintl</span><span>llrint</span><span>llrintf</span><span>llrintl</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><span class="t-mark-rev t-since-c99">(C99)</span></span><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><span class="t-mark-rev t-since-c99">(C99)</span></span><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><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> rounds to an integer using current rounding mode with <br> exception if the result differs <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="round" title="c/numeric/math/round"> <span class="t-lines"><span>round</span><span>roundf</span><span>roundl</span><span>lround</span><span>lroundf</span><span>lroundl</span><span>llround</span><span>llroundf</span><span>llroundl</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><span class="t-mark-rev t-since-c99">(C99)</span></span><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><span class="t-mark-rev t-since-c99">(C99)</span></span><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><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> rounds to nearest integer, rounding away from zero in halfway cases <br> <span class="t-mark">(function)</span>  </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/numeric/math/roundeven" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/roundeven</a>
  </p>
</div>