C++ Math fdim()
C++ Math fdim()
该函数计算两个数字之间的正差。
条件:
考虑两个数字'x'和'y':
If(x> y): 返回(xy);
If(y> x ): 它返回零。
语法
float fdim(float x, float y);
double fdim(double x, double y);
long double fdim(long double x, long double y);
promoted fdim(Arithmetic x, Arithmetic y);
注意: 如果任何参数具有整数类型,则将其强制转换为double。如果任何其他参数是long double,则将其强制转换为long double。
参数
(x,y): 要计算其差值的值。
返回值
它返回x和y之间的正差。
示例1
让我们看看一个简单的示例,其中" x"的值大于" y"的值。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=9.4;
float y=8.3;
std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
cout<<"Positive difference between two numbers is :"<<fdim(x,y);
return 0;
}
输出:
Values of x and y are :9.4,8.3
Positive difference between two numbers is :1.1
在此示例中,x的值大于y的值,并且fdim()函数找到x和y之间的正差。
示例2
让我们看一个简单的例子,当'x'的值小于'y'的值时。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x=3.3;
float y= 4.7;
std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
cout<<"Positive difference between two numbers is :"<<fdim(x,y);
return 0;
}
输出:
Values of x and y are :3.3,4.7
Positive difference between two numbers is :0
在此示例中,x的值小于y的值,因此fdim()函数返回零值。