该函数返回两个数字之间的最小值。
条件:
考虑两个数字 'x' 和 'y'。
如果(x
如果(x>y): 它返回 y。
如果(x=nan): 它返回 y。
如果(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 的值。
相关用法
- C++ Math fma()用法及代码示例
- C++ Math fmax()用法及代码示例
- C++ Math fmod()用法及代码示例
- C++ Math fabs()用法及代码示例
- C++ Math fdim()用法及代码示例
- C++ Math fpclassify()用法及代码示例
- C++ Math frexp()用法及代码示例
- C++ Math floor()用法及代码示例
- C++ Math scalbn()用法及代码示例
- C++ Math acosh()用法及代码示例
- C++ Math asinh()用法及代码示例
- C++ Math isgreater()用法及代码示例
- C++ Math islessgreater()用法及代码示例
- C++ Math log2()用法及代码示例
- C++ Math nearbyint()用法及代码示例
- C++ Math tan()用法及代码示例
- C++ Math log()用法及代码示例
- C++ Math nextafter()用法及代码示例
- C++ Math isfinite()用法及代码示例
- C++ Math erfc()用法及代码示例
注:本文由纯净天空筛选整理自 C++ Math fmin()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。