1 /*
2 Copyright (c) 1990 Regents of the University of California.
3 All rights reserved.
4 */
5 /*
6 FUNCTION
7 <<abs>>---integer absolute value (magnitude)
8
9 INDEX
10 abs
11
12 SYNOPSIS
13 #include <stdlib.h>
14 int abs(int <[i]>);
15
16 DESCRIPTION
17 <<abs>> returns
18 @tex
19 $|x|$,
20 @end tex
21 the absolute value of <[i]> (also called the magnitude
22 of <[i]>). That is, if <[i]> is negative, the result is the opposite
23 of <[i]>, but if <[i]> is nonnegative the result is <[i]>.
24
25 The similar function <<labs>> uses and returns <<long>> rather than <<int>> values.
26
27 RETURNS
28 The result is a nonnegative integer.
29
30 PORTABILITY
31 <<abs>> is ANSI.
32
33 No supporting OS subroutines are required.
34 */
35
36 #include <stdlib.h>
37
38 int
abs(int i)39 abs (int i)
40 {
41 return (i < 0) ? -i : i;
42 }
43