C ++中的fdim()
在这里,我们将看到fdim()
C++中的功能是什么。该fdim()
函数用于返回两个给定参数之间的正差。如果两个参数分别是a和b,并且如果a>b,则它将返回a–b。否则返回0。
示例
#include <cmath> #include <iostream> using namespace std; main() { cout << "fdim of (5.0, 2.0) is " << fdim(5.0, 2.0) << endl; //positive difference cout << "fdim of (2.0, 5.0) is " << fdim(2.0, 5.0) << endl; //this will return 0 cout << "fdim of (-5.0, -2.0) is " << fdim(-5.0, -2.0) << endl; //this will return 0 cout << "fdim of (-2.0, -5.0) is " << fdim(-2.0, -5.0) << endl; //positive difference }
输出结果
fdim of (5.0, 2.0) is 3 fdim of (2.0, 5.0) is 0 fdim of (-5.0, -2.0) is 0 fdim of (-2.0, -5.0) is 3