1ABS(3) Linux Programmer's Manual ABS(3)
2
3
4
6 abs, labs, llabs, imaxabs - compute the absolute value of an integer
7
9 #include <stdlib.h>
10
11 int abs(int j);
12 long labs(long j);
13 long long llabs(long long j);
14
15 #include <inttypes.h>
16
17 intmax_t imaxabs(intmax_t j);
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 llabs():
22 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
23
25 The abs() function computes the absolute value of the integer argument
26 j. The labs(), llabs(), and imaxabs() functions compute the absolute
27 value of the argument j of the appropriate integer type for the func‐
28 tion.
29
31 Returns the absolute value of the integer argument, of the appropriate
32 integer type for the function.
33
35 For an explanation of the terms used in this section, see at‐
36 tributes(7).
37
38 ┌────────────────────────────────────────────┬───────────────┬─────────┐
39 │Interface │ Attribute │ Value │
40 ├────────────────────────────────────────────┼───────────────┼─────────┤
41 │abs(), labs(), llabs(), imaxabs() │ Thread safety │ MT-Safe │
42 └────────────────────────────────────────────┴───────────────┴─────────┘
43
45 POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD. C89 only includes the
46 abs() and labs() functions; the functions llabs() and imaxabs() were
47 added in C99.
48
50 Trying to take the absolute value of the most negative integer is not
51 defined.
52
53 The llabs() function is included in glibc since version 2.0. The imax‐
54 abs() function is included in glibc since version 2.1.1.
55
56 For llabs() to be declared, it may be necessary to define
57 _ISOC99_SOURCE or _ISOC9X_SOURCE (depending on the version of glibc)
58 before including any standard headers.
59
60 By default, GCC handles abs(), labs(), and (since GCC 3.0) llabs() and
61 imaxabs() as built-in functions.
62
64 cabs(3), ceil(3), fabs(3), floor(3), rint(3)
65
67 This page is part of release 5.12 of the Linux man-pages project. A
68 description of the project, information about reporting bugs, and the
69 latest version of this page, can be found at
70 https://www.kernel.org/doc/man-pages/.
71
72
73
74GNU 2021-03-22 ABS(3)