6.11.60 fdimf Function
Calculates the positive difference between two single-precision floating-point arguments.
Include
<math.h>
Prototype
float fdimf(float x, float y);
Arguments
x
- any single-precision floating-point number
y
- any single-precision floating-point number
Return Value
Returns the positive difference between the two arguments, that being x -
y
when x
is larger than y
, and 0 for all
other values of x
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
float x, y, z;
errno = 0;
x = 5.7;
y = 2.0;
z = fdimf(x, y);
if(errno)
perror("Error");
printf("The positive difference between %f and %f is %f\n", x, y, z);
errno = 0;
x = 3.0;
y = 4.2;
z = fdimf(x, y);
if(errno)
perror("Error");
printf("The positive difference between %f and %f is %f\n", x, y, z);
}
Example Output
The positive difference between 5.700000 and 2.000000 is 3.700000
The positive difference between 3.000000 and 4.200000 is 0.000000