]>
Commit | Line | Data |
---|---|---|
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) | |
2 | .\" | |
3 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft | |
4 | .\" | |
5 | .\" References consulted: | |
6 | .\" Linux libc source code | |
7 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
8 | .\" 386BSD man pages | |
9 | .\" Modified Mon Mar 29 22:31:13 1993, David Metcalfe | |
10 | .\" Modified Sun Jun 6 23:27:50 1993, David Metcalfe | |
11 | .\" Modified Sat Jul 24 21:45:37 1993, Rik Faith (faith@cs.unc.edu) | |
12 | .\" Modified Sat Dec 16 15:02:59 2000, Joseph S. Myers | |
13 | .\" | |
14 | .TH ABS 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual" | |
15 | .SH NAME | |
16 | abs, labs, llabs, imaxabs \- compute the absolute value of an integer | |
17 | .SH LIBRARY | |
18 | Standard C library | |
19 | .RI ( libc ", " \-lc ) | |
20 | .SH SYNOPSIS | |
21 | .nf | |
22 | .B #include <stdlib.h> | |
23 | .PP | |
24 | .BI "int abs(int " j ); | |
25 | .BI "long labs(long " j ); | |
26 | .BI "long long llabs(long long " j ); | |
27 | .PP | |
28 | .B #include <inttypes.h> | |
29 | .PP | |
30 | .BI "intmax_t imaxabs(intmax_t " j ); | |
31 | .fi | |
32 | .PP | |
33 | .RS -4 | |
34 | Feature Test Macro Requirements for glibc (see | |
35 | .BR feature_test_macros (7)): | |
36 | .RE | |
37 | .PP | |
38 | .BR llabs (): | |
39 | .nf | |
40 | _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L | |
41 | .fi | |
42 | .SH DESCRIPTION | |
43 | The | |
44 | .BR abs () | |
45 | function computes the absolute value of the integer | |
46 | argument \fIj\fP. | |
47 | The | |
48 | .BR labs (), | |
49 | .BR llabs (), | |
50 | and | |
51 | .BR imaxabs () | |
52 | functions compute the absolute value of the argument \fIj\fP of the | |
53 | appropriate integer type for the function. | |
54 | .SH RETURN VALUE | |
55 | Returns the absolute value of the integer argument, of the appropriate | |
56 | integer type for the function. | |
57 | .SH ATTRIBUTES | |
58 | For an explanation of the terms used in this section, see | |
59 | .BR attributes (7). | |
60 | .ad l | |
61 | .nh | |
62 | .TS | |
63 | allbox; | |
64 | lbx lb lb | |
65 | l l l. | |
66 | Interface Attribute Value | |
67 | T{ | |
68 | .BR abs (), | |
69 | .BR labs (), | |
70 | .BR llabs (), | |
71 | .BR imaxabs () | |
72 | T} Thread safety MT-Safe | |
73 | .TE | |
74 | .hy | |
75 | .ad | |
76 | .sp 1 | |
77 | .SH STANDARDS | |
78 | POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD. | |
79 | .\" POSIX.1 (1996 edition) requires only the | |
80 | .\" .BR abs () | |
81 | .\" function. | |
82 | C89 only | |
83 | includes the | |
84 | .BR abs () | |
85 | and | |
86 | .BR labs () | |
87 | functions; the functions | |
88 | .BR llabs () | |
89 | and | |
90 | .BR imaxabs () | |
91 | were added in C99. | |
92 | .SH NOTES | |
93 | Trying to take the absolute value of the most negative integer | |
94 | is not defined. | |
95 | .PP | |
96 | The | |
97 | .BR llabs () | |
98 | function is included in glibc since version 2.0. | |
99 | The | |
100 | .BR imaxabs () | |
101 | function is included in | |
102 | glibc since version 2.1.1. | |
103 | .PP | |
104 | For | |
105 | .BR llabs () | |
106 | to be declared, it may be necessary to define | |
107 | \fB_ISOC99_SOURCE\fP or \fB_ISOC9X_SOURCE\fP (depending on the | |
108 | version of glibc) before including any standard headers. | |
109 | .PP | |
110 | By default, | |
111 | GCC handles | |
112 | .BR abs (), | |
113 | .BR labs (), | |
114 | and (since GCC 3.0) | |
115 | .BR llabs () | |
116 | and | |
117 | .BR imaxabs () | |
118 | as built-in functions. | |
119 | .SH SEE ALSO | |
120 | .BR cabs (3), | |
121 | .BR ceil (3), | |
122 | .BR fabs (3), | |
123 | .BR floor (3), | |
124 | .BR rint (3) |