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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP