English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++uses two parameters and returns the largest one. If one of the parameters is NAN, it returns the other parameter.
The function in<cmath>defined in the header file.
double fmax(double x, double y); float fmax(float x, float y); long double fmax(long double x, long double y); Promoted fmax(Type1 x, Type2 y); // other overloaded arithmetic types
From C ++ 11Starting from C, if the parameters passed to fmax() are of type long double, the returned type Promoted is long double. If not, the returned type Promoted is double.
x: The first parameter of fmax().
y: The second parameter of fmax().
The fmax() function returns the maximum value between x and y.
#include <iostream> #include <cmath> using namespace std; int main() { double x = -2.05, y = NAN, result; result = fmax(x, y); cout << "fmax(x, y) = " << result << endl; return 0; }
The output when running the program is:
fmax(x, y) = -2.05
#include <iostream> #include <cmath> using namespace std; int main() { double x = 56.13, result; int y = 89; result = fmax(x, y); cout << "fmax(x, y) = " << result << endl; return 0; }
The output when running the program is:
fmax(x, y) = 89