xref: /freebsd/lib/libc/stdlib/abs.3 (revision 32cd3ee5901ea33d41ff550e5f40ce743c8d4165)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\" Copyright (c) 2026 Aymeric Wibo <obiwac@freebsd.org>
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" the American National Standards Committee X3, on Information
7.\" Processing Systems.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.Dd February 19, 2026
34.Dt ABS 3
35.Os
36.Sh NAME
37.Nm abs ,
38.Nm labs ,
39.Nm llabs ,
40.Nm imaxabs
41.Nd return absolute value for integer types
42.Sh SYNOPSIS
43.Lb libc
44.In stdlib.h
45.Ft int
46.Fn abs "int i"
47.Ft long
48.Fn labs "long i"
49.Ft long long
50.Fn llabs "long long i"
51.In inttypes.h
52.Ft intmax_t
53.Fn imaxabs "intmax_t i"
54.Sh DESCRIPTION
55The
56.Fn abs ,
57.Fn labs ,
58.Fn llabs ,
59and
60.Fn imaxabs
61functions compute the absolute value of
62.Fa i .
63.Sh RETURN VALUES
64The
65.Fn abs ,
66.Fn labs ,
67.Fn llabs ,
68and
69.Fn imaxabs
70functions return the absolute value.
71.Sh SEE ALSO
72.Xr cabs 3 ,
73.Xr fabs 3 ,
74.Xr floor 3 ,
75.Xr hypot 3
76.Sh STANDARDS
77The
78.Fn abs ,
79.Fn labs ,
80.Fn llabs ,
81and
82.Fn imaxabs
83functions conform to
84.St -isoC-2023
85and
86.St -p1003.1-2024 .
87.Sh HISTORY
88The
89.Fn abs
90function first appeared in
91.At v6 .
92The
93.Fn labs
94function first appeared in
95.Bx 4.3 .
96The
97.Fn llabs
98and
99.Fn imaxabs
100functions first appeared in
101.Fx 5.0 .
102.Sh BUGS
103The absolute value of the most negative integer remains negative.
104