fabs(3C)
_________________________________________________________________
fabs $builtin function
Determine the absolute value of a floating-point number.
_________________________________________________________________
Calling Sequence
double m, n, fabs();
m = fabs(n);
(or)
$builtin double fabs();
double m, n;
m = fabs(n);
where m and n are of type double.
Description
Use the fabs function to determine the absolute value of a number
that is type double. It is the same as the abs function, except
that abs returns the absolute value of an integer.
The first version noted above uses a function call. The second
might generate smaller or faster code, but may not run under
other C compilers.
The include file math.h defines this function and uses the
$builtin version. Using the include file will not cause any
portability problems.
Returns
The fabs function returns the absolute value of the number you
pass.
Related Functions
See also the abs function.
Example
/* Program test for the fabs() function */
#include <math.h>
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
fabs(3C)
int i = 1;
double m, n, atof(), fabs();
main(argc, argv)
int argc;
char *argv[];
{
while (i < argc) {
n = atof(argv[i]);
printf("Absolute value of %f = %f\n",
n, m = fabs(n));
i++;
}
}
If you call the program test with the input numbers
12.3e-2
-34.5e-2
-.9999
2.718281
3.14159
you generate the output
Absolute value of 0.123000= 0.123000
Absolute value of -0.345000= 0.345000
Absolute value of -0.999900= 0.999900
Absolute value of 2.718281= 2.718281
Absolute value of 3.141590= 3.141590
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)