C Math fdim() Function
Example
Return the positive difference between two numbers:
printf("%f\n", fdim(10.5, 4.0));
printf("%f", 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 <math.h> header file.
Syntax
double fdim(double x, double y);
There are also versions for float and long double values: fdimf() and fdiml().
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 C Math Tutorial.