📌  相关文章
📜  C++ fdim()

📅  最后修改于: 2020-09-25 07:36:53             🧑  作者: Mango

C++中的fdim() 函数采用两个参数,并返回第一个和第二个参数之间的正差。

fdim()原型[从C++ 11标准开始]

double fdim(double x, double y);
float fdim(float x, float y);
long double fdim(long double x, long double y);
Promoted fdim(Type1 x, Type2 y); // For other combinations of arithmetic types.

从C++ 11开始,如果传递给fdim()的任何参数为long double ,则返回的Promoted类型为long double 。如果不是,则返回类型Promoteddouble

此函数在头文件中定义。

fdim()参数

fdim() 函数采用两个浮点或整数类型的参数:

fdim()返回值

fdim() 函数返回:

示例:fdim()如何工作?

#include 
#include 
using namespace std;

int main()
{
    double x = 22.31, y = 13.17, result;
    result = fdim(x, y);
    cout << "fdim(x, y) = " << result << endl;

    long double xLD = -22.31, resultLD;
    y = 13.14;
    resultLD = fdim(xLD, y);
    cout << "fdim(xLD, y) = " << resultLD << endl;
        
    return 0;
}

运行该程序时,输出为:

fdim(x, y) = 9.14
fdim(xLD, yLD) = 0