Namespaces
Variants

std::abs, std::labs, std::llabs, std::imaxabs

From cppreference.com
 
 
 
Common mathematical functions
Functions
Basic operations
(C++11)    
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Exponential functions
(C++11)
(C++11)

(C++11)
(C++11)
Power functions
(C++11)
(C++11)
Trigonometric and
hyperbolic functions
(C++11)
(C++11)
(C++11)

Error and gamma functions
(C++11)
(C++11)
(C++11)
(C++11)
Nearest integer floating point operations
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Floating point manipulation functions
(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++26)(C++26)
(C++11)
Classification and comparison
(C++11)    
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
(C++11)
(C++11)
(C++26)(C++26)(C++26)

 
Defined in header <cstdlib>
Defined in header <cmath>
int       abs( int num );
(1) (constexpr since C++23)
long      abs( long num );
(2) (constexpr since C++23)
long long abs( long long num );
(3) (since C++11)
(constexpr since C++23)
Defined in header <cstdlib>
long       labs( long num );
(4) (constexpr since C++23)
long long llabs( long long num );
(5) (since C++11)
(constexpr since C++23)
Defined in header <cinttypes>
std::intmax_t abs( std::intmax_t num );
(6) (since C++11)
(constexpr since C++23)
std::intmax_t imaxabs( std::intmax_t num );
(7) (since C++11)
(constexpr since C++23)

Computes the absolute value of the integer number num. The behavior is undefined if the result cannot be represented by the return type.

If std::abs is called with an unsigned integral argument that cannot be converted to int by integral promotion, the program is ill-formed.

Overload (6) of std::abs for std::intmax_t is provided in <cinttypes> if and only if std::intmax_t is an extended integer type.

(since C++11)

Parameters

num - integer value

Return value

The absolute value of num (i.e.