1abs(3) Library Functions Manual abs(3)
2
3
4
6 abs, labs, llabs, imaxabs - compute the absolute value of an integer
7
9 Standard C library (libc, -lc)
10
12 #include <stdlib.h>
13
14 int abs(int j);
15 long labs(long j);
16 long long llabs(long long j);
17
18 #include <inttypes.h>
19
20 intmax_t imaxabs(intmax_t j);
21
22 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
23
24 llabs():
25 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
26
28 The abs() function computes the absolute value of the integer argument
29 j. The labs(), llabs(), and imaxabs() functions compute the absolute
30 value of the argument j of the appropriate integer type for the func‐
31 tion.
32
34 Returns the absolute value of the integer argument, of the appropriate
35 integer type for the function.
36
38 For an explanation of the terms used in this section, see at‐
39 tributes(7).
40
41 ┌────────────────────────────────────────────┬───────────────┬─────────┐
42 │Interface │ Attribute │ Value │
43 ├────────────────────────────────────────────┼───────────────┼─────────┤
44 │abs(), labs(), llabs(), imaxabs() │ Thread safety │ MT-Safe │
45 └────────────────────────────────────────────┴───────────────┴─────────┘
46
48 C11, POSIX.1-2008.
49
51 POSIX.1-2001, C99, SVr4, 4.3BSD.
52
53 C89 only includes the abs() and labs() functions; the functions llabs()
54 and imaxabs() were added in C99.
55
57 Trying to take the absolute value of the most negative integer is not
58 defined.
59
60 The llabs() function is included since glibc 2.0. The imaxabs() func‐
61 tion is included since glibc 2.1.1.
62
63 For llabs() to be declared, it may be necessary to define
64 _ISOC99_SOURCE or _ISOC9X_SOURCE (depending on the version of glibc)
65 before including any standard headers.
66
67 By default, GCC handles abs(), labs(), and (since GCC 3.0) llabs() and
68 imaxabs() as built-in functions.
69
71 cabs(3), ceil(3), fabs(3), floor(3), rint(3)
72
73
74
75Linux man-pages 6.04 2023-03-30 abs(3)