该函数返回两个数字之间的最大值。
考虑两个数字" 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.
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);
(x,y) : 在其中计算最大值的值。
它返回两个数字之间的最大值。
让我们看一个简单的例子。
#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的值。
让我们看一个简单的示例,其中一个值是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的值。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)