C++ cmath fdim() Function
Example
Return the positive difference between two numbers:
cout << fdim(10.5, 4.0) << "\n";
cout << fdim(4.0, 10.5);
Definition and Usage
The fdim() function returns x - y if x is bigger than y. Otherwise, it returns 0.
This means that the result is never negative.
The fdim function is defined in the <cmath> header file.
Syntax
fdim(double x, double y)
The function also works with float and long double values. Then it returns a value of the same type.
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. The number to subtract from. |
| y | Required. The number to subtract. |
Technical Details
| Returns: | A double value with the positive difference, or 0. |
|---|
Related Pages
Read more about math in our Math Tutorial.