C++ Math fmin()
C++ Math fmin()
该函数返回两个数字之间的最小值。
条件:
请考虑两个数字" x"和" y"。
If(x < y): 返回x。
If(x> y): 返回y。
If(x = nan): 返回y。
If(y = nan): 返回x。
语法
float fmin(float x, float y);
double fmin(double x, double y);
long double fmin(long double x, long double y);
promoted fmin(Arithmetic x, Arithmetic y);
注意: 如果任何参数具有整数类型,则将其强制转换为double。如果任何其他参数是long double,则将其强制转换为long double。
参数
(x,y): 要在其中计算最小值的值。
返回值
它返回两个数字之间的最小值。
示例1
让我们看到一个简单的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=1.1;
float y=2.1;
std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
cout<<"Minimum value is :"<<fmin(x,y);
return 0;
}
输出:
Values of x and y are :1.1,2.1
Minimum value is :1.1
在此示例中,x的值小于y的值。因此,fmin()函数返回x的值。
示例2
让我们看一个简单的示例,其中一个值是nan。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=10.1;
double y=NAN;
std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
cout<<"Minimum value is :"<<fmin(x,y);
return 0;
}
输出:
Values of x and y are :10.1,nan
Minimum value is :10.1
在此示例中,y的值为nan。因此,将返回x的值。