該函數計算兩個數字之間的正差。
條件:
考慮兩個數字 'x' 和 'y':
如果(x>y): 它返回 (x-y);
如果(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() 函數返回零值。
相關用法
- C++ Math fabs()用法及代碼示例
- C++ Math fma()用法及代碼示例
- C++ Math fpclassify()用法及代碼示例
- C++ Math fmin()用法及代碼示例
- C++ Math frexp()用法及代碼示例
- C++ Math fmax()用法及代碼示例
- C++ Math floor()用法及代碼示例
- C++ Math fmod()用法及代碼示例
- 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 fdim()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。