C++官网参考链接:https://cplusplus.com/reference/cmath/fmax/
函数
<cmath> <ctgmath>
fmax
C99
double fmax(double x, double y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
C++11
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
最大值
返回实参中的更大值,x或者y。
如果其中一个实参在NaN中,则返回另一个实参。
C99
头文件<tgmath.h>提供了该函数的类型泛型宏版本。
C++11
这个头文件(<cmath>)为其他算术类型(arithmetic types)(Type1和Type2)的组合提供了额外的重载:这些重载在计算之前有效地将其实参转换为double类型,除非至少有一个实参是long double类型(在这种情况下,两个实参都被转换为long double类型)。
形参
x,y
函数在其中选择最大值的值。
返回值
实参中的最大数值。
用例
/* 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;
}
输出:
另请参考
fmin Minimum value (function) (最小值(函数))
fdim Positive difference (function) (正差(函数))