[c.math.abs]

# 29 Numerics library [[numerics]](./#numerics)

## 29.7 Mathematical functions for floating-point types [[c.math]](c.math#abs)

### 29.7.2 Absolute values [c.math.abs]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9843)

[*Note [1](#note-1)*:

The headers [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") and[<cmath>](cmath.syn#header:%3ccmath%3e "29.7.1 Header <cmath> synopsis [cmath.syn]") declare the functions described in this subclause[.](#1.sentence-1)

â *end note*]

[ð](#lib:abs)

`constexpr int abs(int j);
constexpr long int abs(long int j);
constexpr long long int abs(long long int j);
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9858)

*Effects*: These
functions have the semantics specified in the C standard library
for the functions abs, labs, and llabs, respectively[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9864)

*Remarks*: If abs is called with an argument of type X for which is_unsigned_v<X> is true and
if X cannot be converted to int by [integral promotion](conv.prom "7.3.7 Integral promotions [conv.prom]"), the program is ill-formed[.](#3.sentence-1)

[*Note [2](#note-2)*:

Allowing arguments that can be promoted to int provides compatibility with C[.](#3.sentence-2)

â *end note*]

[ð](#itemdecl:2)

`constexpr floating-point-type abs(floating-point-type x);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9881)

*Returns*: The absolute value of x[.](#4.sentence-1)

See also: ISO/IEC 9899:2024, 7.12.7.2, 7.22.6.1
