GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::abs,std::labs,std::llabs,std::imaxabs(3) C++ Standard Libary std::abs,std::labs,std::llabs,std::imaxabs(3)

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


Defined in header <cstdlib>
Defined in header <cmath>
int abs( int n ); (1) (constexpr since C++23)
long abs( long n ); (2) (constexpr since C++23)
long long abs( long long n ); (3) (since C++11)
(constexpr since C++23)
Defined in header <cstdlib>
long labs( long n ); (4) (constexpr since C++23)
long long llabs( long long n ); (5) (since C++11)
(constexpr since C++23)
Defined in header <cinttypes>
std::intmax_t abs( std::intmax_t n ); (6) (since C++11)
std::intmax_t imaxabs( std::intmax_t n ); (7) (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 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> (since C++11)
if and only if std::intmax_t is an extended integer type.


n - integer value


The absolute value of n (i.e. |n|), if it is representable.


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.

// Run this code


#include <iostream>
#include <cstdlib>
#include <climits>


int main()
{
std::cout << std::showpos
<< "abs(+3) = " << std::abs(3) << '\n'
<< "abs(-3) = " << std::abs(-3) << '\n';


// std::cout << std::abs(INT_MIN); // undefined behavior on 2's complement systems
}


abs(+3) = +3
abs(-3) = +3


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
overloads of std::abs were declared these overloads in
LWG 2192 C++98 inconsistently both headers
declared in two headers


abs(float)
fabs
fabsf absolute value of a floating point value (\(\small{|x|}\)|x|)
fabsl (function)
(C++11)
(C++11)
abs(std::complex) returns the magnitude of a complex number
(function template)
abs(std::valarray) applies the function abs to each element of valarray
(function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.