C++ Standard Library C++ STL Library

C++ <cmath> - fmax() Function



The C++ <cmath> fmax() function returns maximum number between the two arguments. If one of the arguments is NaN, then the other argument is returned.

Syntax

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);                                  

Parameters

x Specify value to compare.
y Specify value to compare.

Return Value

Returns the numerically maximum value.

Example:

In the example below, fmax() function is used to find out the maximum value between the two arguments.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<fmax(50, 100)<<"\n";
  cout<<fmax(5.5, 10.5)<<"\n";
  cout<<fmax(-2, 2)<<"\n"; 
  cout<<fmax(-3, -2)<<"\n";  
  return 0;
}

The output of the above code will be:

100
10.5
2
-2

❮ C++ <cmath> Library

5