fdimf - Linux
Overview
fdimf computes the positive difference between two floating-point numbers. It determines the difference between two numbers by subtracting the smaller from the larger, and if the result is negative, returns zero.
Syntax
fdimf(x, y)
- x: The first floating-point number.
- y: The second floating-point number.
Options/Flags
None
Examples
Example 1: Subtracting 2.5 from 5.0
fdimf(5.0, 2.5)
Output:
2.5
Example 2: Subtracting 8.7 from 2.1
fdimf(2.1, 8.7)
Output:
0
Common Issues
- If either input is NaN, the result is NaN.
- If both inputs are negative, the result is zero.
Integration
fdimf can be combined with other commands to perform more complex operations. For instance, it can be used to implement a clamp function:
clamp(min, value, max) {
return fdimf(fdimf(value, max), fdimf(min, value));
}
Related Commands
- fabs: Computes the absolute value of a floating-point number.
- fmax: Returns the larger of two floating-point numbers.
- fmin: Returns the smaller of two floating-point numbers.