1 /*
2 Copyright (c) 1990 Regents of the University of California.
3 All rights reserved.
4 */
5 /*
6 FUNCTION
7 <<labs>>---long integer absolute value
8
9 INDEX
10 labs
11
12 SYNOPSIS
13 #include <stdlib.h>
14 long labs(long <[i]>);
15
16 DESCRIPTION
17 <<labs>> 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 <<abs>> uses and returns <<int>> rather than
26 <<long>> values.
27
28 RETURNS
29 The result is a nonnegative long integer.
30
31 PORTABILITY
32 <<labs>> is ANSI.
33
34 No supporting OS subroutine calls are required.
35 */
36
37 #include <stdlib.h>
38
39 long
labs(long x)40 labs (long x)
41 {
42 if (x < 0)
43 {
44 x = -x;
45 }
46 return x;
47 }
48