abs(3C)
_________________________________________________________________
abs $builtin function
Return the absolute value of an integer.
_________________________________________________________________
Calling Sequence
int m, n, abs();
m = abs(n);
(or)
$builtin int abs();
int m, n;
m = abs(n);
where m and n are integer variables.
Description
Use the abs function to return the absolute value of an integer.
This function is the same as fabs, except that fabs returns the
absolute value of a number of type double rather than an integer.
The first calling sequence 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 the abs function and uses the
$builtin version. Using the include file will not cause any
portability problems.
Returns
This function does not check for an integer value. It returns
the absolute value of the integer you pass to it.
Related Functions
See also the fabs function.
Example
/* Program test for the abs() function */
#include <stdio.h>
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
abs(3C)
#include <math.h>
int atoi(), m, n, abs();
main(argc, argv)
int argc;
char *argv[];
{
n = atoi(argv[1]);
printf("n = %d has absolute value m = %d.\n", n, m = abs(n));
}
If you call the program test with an argument of -13, the output
will be the following:
n = -13 has absolute value m = 13.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)