fmax(x,y)函数详解

首页 / C++入门教程 / fmax(x,y)函数详解

该函数返回两个数字之间的最大值。

考虑两个数字" 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的值。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

微服务架构核心20讲 -〔杨波〕

从0开始学大数据 -〔李智慧〕

从0打造音视频直播系统 -〔李超〕

雷蓓蓓的项目管理实战课 -〔雷蓓蓓〕

安全攻防技能30讲 -〔何为舟〕

小马哥讲Spring核心编程思想 -〔小马哥〕

重学线性代数 -〔朱维刚〕

说透元宇宙 -〔方军〕

互联网人的数字化企业生存指南 -〔沈欣〕

好记忆不如烂笔头。留下您的足迹吧 :)