std::abs,std::labs,std::llabs,std::imaxabs (3) - Linux Manuals
std::abs,std::labs,std::llabs,std::imaxabs: std::abs,std::labs,std::llabs,std::imaxabs
NAME
std::abs,std::labs,std::llabs,std::imaxabs - std::abs,std::labs,std::llabs,std::imaxabs
Synopsis
Defined in header <cstdlib>
Defined in header <cmath> (since C++17)
int abs( int n );
long abs( long n );
long long abs( long long n ); (since C++11)
Defined in header <cstdlib>
long labs( long n );
long long llabs( long long n ); (since C++11)
Defined in header <cinttypes>
std::intmax_t abs( std::intmax_t n ); (since C++11)
std::intmax_t imaxabs( std::intmax_t n ); (since C++11)
Computes the absolute value of an integer number. The behavior is undefined if the result cannot be represented by the return type.
If std::abs is called with an argument of type X such that std::is_unsigned<X>::value is true and X cannot be converted to int by integral_promotion, the program is ill-formed. (since C++17)
Parameters
n - integer value
Return value
The absolute value of n (i.e. |n|), if it is representable.
Notes
In 2's complement systems, the absolute value of the most-negative value is out of range, e.g. for 32-bit 2's complement type int, INT_MIN is -2147483648, but the would-be result 2147483648 is greater than INT_MAX, which is 2147483647.
Example
// Run this code
Output:
See also
abs(float)
fabs
fabsf
fabsl absolute value of a floating point value (|x|)
(C++11)
(C++11)
abs(std::complex) (function template)
abs(std::valarray) (function template)