summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fmath%2Ffmax.html
blob: 899bbddd51fd2a34f5ff9b2a918e0b219bfe8bb2 (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
    <h1 id="firstHeading" class="firstHeading">fmax, fmaxf, fmaxl</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-c99"> <td> <pre data-language="c">float       fmaxf( float x, float y );</pre>
</td> <td> (1) </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">double      fmax( double x, double y );</pre>
</td> <td> (2) </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 fmaxl( long double x, long double y );</pre>
</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</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-c99"> <td> <pre data-language="c">#define fmax( x, y )</pre>
</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr>  </table> <div class="t-li1">
<span class="t-li">1-3)</span> Returns the larger of two floating point arguments, treating NaNs as missing data (between a NaN and a numeric value, the numeric value is chosen).</div> <div class="t-li1">
<span class="t-li">4)</span> Type-generic macro: If any argument has type <code>long double</code>, <code>fmaxl</code> is called. Otherwise, if any argument has integer type or has type <code>double</code>, <code>fmax</code> is called. Otherwise, <code>fmaxf</code> is called.</div>  <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> x, y </td> <td> - </td> <td> floating point values </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>If successful, returns the larger of two floating point values. The value returned is exact and does not depend on any rounding modes.</p>
<h3 id="Error_handling"> Error handling</h3> <p>This function is not subject to any of the error conditions 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> If one of the two arguments is NaN, the value of the other argument is returned. </li>
<li> Only if both arguments are NaN is NaN returned. </li>
</ul> <h3 id="Notes"> Notes</h3> <p>This function is not required to be sensitive to the sign of zero, although some implementations additionally enforce that if one argument is +0 and the other is -0, then +0 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;math.h&gt;
 
int main(void)
{
    printf("fmax(2,1)    = %f\n", fmax(2,1));
    printf("fmax(-Inf,0) = %f\n", fmax(-INFINITY,0));
    printf("fmax(NaN,-1) = %f\n", fmax(NAN,-1));
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">fmax(2,1)    = 2.000000
fmax(-Inf,0) = 0.000000
fmax(NaN,-1) = -1.000000</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul>
<li> 7.12.12.2 The fmax functions (p: 188) </li>
<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 397) </li>
<li> F.10.9.2 The fmax functions (p: 386) </li>
</ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul>
<li> 7.12.12.2 The fmax functions (p: 257-258) </li>
<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </li>
<li> F.10.9.2 The fmax functions (p: 530) </li>
</ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul>
<li> 7.12.12.2 The fmax functions (p: 238-239) </li>
<li> 7.22 Type-generic math &lt;tgmath.h&gt; (p: 335-337) </li>
<li> F.9.9.2 The fmax functions (p: 466) </li>
</ul>
</ul>                 <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="isgreater" title="c/numeric/math/isgreater"> <span class="t-lines"><span>isgreater</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> checks if the first floating-point argument is greater than the second <br> <span class="t-mark">(function macro)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="fmin" title="c/numeric/math/fmin"> <span class="t-lines"><span>fmin</span><span>fminf</span><span>fminl</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></div> </td> <td> determines smaller of two floating-point values <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/numeric/math/fmax" title="cpp/numeric/math/fmax">C++ documentation</a></span> for <code>fmax</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/numeric/math/fmax" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/fmax</a>
  </p>
</div>