function
<cmath> <ctgmath>

fmax

     double fmax  (double x     , double y);
      float fmaxf (float x      , float y);
long double fmaxl (long double x, long double y);
     double fmax (double x     , double y);
      float fmax (float x      , float y);
long double fmax (long double x, long double y);
     double fmax (Type1 x      , Type2 y);       // additional overloads
Maximum value
Returns the larger of its arguments: either x or y.

If one of the arguments in a NaN, the other is returned.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for other combinations of arithmetic types (Type1 and Type2): These overloads effectively cast its arguments to double before calculations, except if at least one of the arguments is of type long double (in which case both are casted to long double instead).

Parameters

x, y
Values among which the function selects a maximum.

Return Value

The maximum numeric value of its arguments.

Example

1
2
3
4
5
6
7
8
9
10
11
/* fmax example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fmax */

int main ()
{
  printf ("fmax (100.0, 1.0) = %f\n", fmax(100.0,1.0));
  printf ("fmax (-100.0, 1.0) = %f\n", fmax(-100.0,1.0));
  printf ("fmax (-100.0, -1.0) = %f\n", fmax(-100.0,-1.0));
  return 0;
}


Output:

fmax (100.0, 1.0) = 100.000000
fmax (-100.0, 1.0) = 1.000000
fmax (-100.0,-1.0) = -1.000000

See also