| 1 |
'\" t |
| 2 |
.\" Copyright 1993 David Metcalfe ([email protected]) |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.\" References consulted: |
| 7 |
.\" Linux libc source code |
| 8 |
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) |
| 9 |
.\" 386BSD man pages |
| 10 |
.\" Modified Mon Mar 29 22:31:13 1993, David Metcalfe |
| 11 |
.\" Modified Sun Jun 6 23:27:50 1993, David Metcalfe |
| 12 |
.\" Modified Sat Jul 24 21:45:37 1993, Rik Faith ([email protected]) |
| 13 |
.\" Modified Sat Dec 16 15:02:59 2000, Joseph S. Myers |
| 14 |
.\" |
| 15 |
.TH abs 3 2024-05-02 "Linux man-pages 6.9.1" |
| 16 |
.SH NAME |
| 17 |
abs, labs, llabs, imaxabs \- compute the absolute value of an integer |
| 18 |
.SH LIBRARY |
| 19 |
Standard C library |
| 20 |
.RI ( libc ", " \-lc ) |
| 21 |
.SH SYNOPSIS |
| 22 |
.nf |
| 23 |
.B #include <stdlib.h> |
| 24 |
.P |
| 25 |
.BI "int abs(int " j ); |
| 26 |
.BI "long labs(long " j ); |
| 27 |
.BI "long long llabs(long long " j ); |
| 28 |
.P |
| 29 |
.B #include <inttypes.h> |
| 30 |
.P |
| 31 |
.BI "intmax_t imaxabs(intmax_t " j ); |
| 32 |
.fi |
| 33 |
.P |
| 34 |
.RS -4 |
| 35 |
Feature Test Macro Requirements for glibc (see |
| 36 |
.BR feature_test_macros (7)): |
| 37 |
.RE |
| 38 |
.P |
| 39 |
.BR llabs (): |
| 40 |
.nf |
| 41 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 42 |
.fi |
| 43 |
.SH DESCRIPTION |
| 44 |
The |
| 45 |
.BR abs () |
| 46 |
function computes the absolute value of the integer |
| 47 |
argument \fIj\fP. |
| 48 |
The |
| 49 |
.BR labs (), |
| 50 |
.BR llabs (), |
| 51 |
and |
| 52 |
.BR imaxabs () |
| 53 |
functions compute the absolute value of the argument \fIj\fP of the |
| 54 |
appropriate integer type for the function. |
| 55 |
.SH RETURN VALUE |
| 56 |
Returns the absolute value of the integer argument, of the appropriate |
| 57 |
integer type for the function. |
| 58 |
.SH ATTRIBUTES |
| 59 |
For an explanation of the terms used in this section, see |
| 60 |
.BR attributes (7). |
| 61 |
.TS |
| 62 |
allbox; |
| 63 |
lbx lb lb |
| 64 |
l l l. |
| 65 |
Interface Attribute Value |
| 66 |
T{ |
| 67 |
.na |
| 68 |
.nh |
| 69 |
.BR abs (), |
| 70 |
.BR labs (), |
| 71 |
.BR llabs (), |
| 72 |
.BR imaxabs () |
| 73 |
T} Thread safety MT-Safe |
| 74 |
.TE |
| 75 |
.SH STANDARDS |
| 76 |
C11, POSIX.1-2008. |
| 77 |
.SH HISTORY |
| 78 |
POSIX.1-2001, C99, SVr4, 4.3BSD. |
| 79 |
.\" POSIX.1 (1996 edition) requires only the |
| 80 |
.\" .BR abs () |
| 81 |
.\" function. |
| 82 |
.P |
| 83 |
C89 only |
| 84 |
includes the |
| 85 |
.BR abs () |
| 86 |
and |
| 87 |
.BR labs () |
| 88 |
functions; the functions |
| 89 |
.BR llabs () |
| 90 |
and |
| 91 |
.BR imaxabs () |
| 92 |
were added in C99. |
| 93 |
.SH NOTES |
| 94 |
Trying to take the absolute value of the most negative integer |
| 95 |
is not defined. |
| 96 |
.P |
| 97 |
The |
| 98 |
.BR llabs () |
| 99 |
function is included since glibc 2.0. |
| 100 |
The |
| 101 |
.BR imaxabs () |
| 102 |
function is included since glibc 2.1.1. |
| 103 |
.P |
| 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 |
.P |
| 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) |