fdim()

Returns the positive difference between two arguments.

Syntax

cmath library must be added at the top of the file.

std:fdim(x, y)

If the first argument is greater than the second argument fdim() returns the first argument minus the second argument, otherwise it returns zero.

Example

double result1;
double result2;
result1 = std::fdim(6, 2); // 4
result2 = std::fdim(4, 8); // 0

Codebyte Example

Use fdim() to return the positive difference between 8 and 5:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn C++ on Codecademy