std::abs(float),std::fabs,std::fabsf,std::fabsl (3) - Linux Manuals
std::abs(float),std::fabs,std::fabsf,std::fabsl: std::abs(float),std::fabs,std::fabsf,std::fabsl
NAME
std::abs(float),std::fabs,std::fabsf,std::fabsl - std::abs(float),std::fabs,std::fabsf,std::fabsl
Synopsis
Defined in header <cmath>
Defined in header <cstdlib> (since C++17)
float abs( float arg ); (1)
double abs( double arg ); (2)
long double abs( long double arg ); (3)
Defined in header <cmath>
float fabs ( float arg );
float fabsf( float arg ); (since C++11)
double fabs ( double arg ); (4) (5)
long double fabs ( long double arg );
long double fabsl( long double arg ); (6) (since C++11)
double fabs ( IntegralType arg ); (7) (since C++11)
1-6) Computes the absolute value of a floating point value arg.
7) A set of overloads or a function template accepting an argument of any integral_type. Equivalent to (5) (the argument is cast to double).
For integral arguments, the_integral_overloads_of_std::abs are likely better matches. 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
arg - Value of a floating-point or Integral_type
Return value
If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.
Error handling
This function is not subject to any of the error conditions specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
* If the argument is ±0, +0 is returned
* If the argument is ±∞, +∞ is returned
* If the argument is NaN, NaN is returned
Example
// Run this code
Possible output:
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2735 C++11 std::abs was erroneously required to have overloads for integer types returning double removed the requirement
See also
abs(int)
labs
llabs computes absolute value of an integral value (|x|)
(C++11)
copysign
copysignf
copysignl copies the sign of a floating point value
(C++11)
(C++11)
(C++11)
signbit checks if the given number is negative
(C++11)
abs(std::complex) (function template)
abs(std::valarray) (function template)