该函数返回两个数字之间的最大值。
考虑两个数字" x"和" y"。
If(x>y): It returns x.If(y>x): It returns y.if (x=nan): It returns y.if (y=nan): It returns x.
fmax - 语法
float fmax(float x, float y); double fmax(double x, double y); long double fmax(long double x, long double y); promoted fmax(Arithmetic x, Arithmetic y);
Note:如果任何参数具有整数类型,则将其强制转换为double。如果任何其他参数是long double,则将其强制转换为long double。
fmax - 参数
(x,y) : 在其中计算最大值的值。
fmax - 返回值
它返回两个数字之间的最大值。
fmax - 例子1
让我们看一个简单的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x=3.3;
float y=6.9;
std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
cout<<"Maximum value is :"<<fmax(x,y);
return 0;
}
输出:
Values of x and y are :3.3,6.9 Maximum value is :6.9
在此示例中,y的值大于x的值。因此,fmax()函数返回y的值。
fmax - 例子2
让我们看一个简单的示例,其中一个值是nan。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x=1.3;
float y=NAN;
std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
cout<<"Maximum value is :"<<fmax(x,y);
return 0;
}
输出:
Values of x and y are :1.3,nan Maximum value is :1.3
在此示例中,y的值为nan。因此,fmax()函数返回x的值。