Calculates the absolute value of a single precision floating-point value.
Include
<math.h>
Prototype
float fabsf(float x);
Argument
x
Return Value
Returns the absolute value of x
. A negative number is
returned as positive; a positive number is unchanged.
Remarks
No domain or range error will occur.
Example
#include <math.h>
#include <stdio.h>
int main(void)
{
float x,y;
x = 1.75F;
y = fabsf (x);
printf("The absolute value of %f is %f\n", x, y);
x = -1.5F;
y = fabsf (x);
printf("The absolute value of %f is %f\n", x, y);
}
Example Output
The absolute value of 1.750000 is 1.750000
The absolute value of -1.500000 is 1.500000