Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library

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


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


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

Return Value

Returns the numerically maximum value.


In the below example, 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:


❮ C++ <cmath> Library