1 /*
2 FUNCTION
3 <<llabs>>---compute the absolute value of an long long integer.
4
5 INDEX
6 llabs
7
8 SYNOPSIS
9 #include <stdlib.h>
10 long long llabs(long long <[j]>);
11
12 DESCRIPTION
13 The <<llabs>> function computes the absolute value of the long long integer
14 argument <[j]> (also called the magnitude of <[j]>).
15
16 The similar function <<labs>> uses and returns <<long>> rather than
17 <<long long>> values.
18
19 RETURNS
20 A nonnegative long long integer.
21
22 PORTABILITY
23 <<llabs>> is ISO 9899 (C99) compatable.
24
25 No supporting OS subroutines are required.
26 */
27
28 /*-
29 * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
30 * All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 */
53
54 #include <stdlib.h>
55
56 long long
llabs(long long j)57 llabs (long long j)
58 {
59 return (j < 0 ? -j : j);
60 }
61