abs, _abs64See Also
Data Conversion Routines | Floating-Point Support | _cabs | fabs | labs | Run-Time Routines and .NET Framework Equivalents
Requirements
Routine Required header Compatibility
abs <stdlib.h> or <math.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
__abs64 <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Calculates the absolute value.
int abs(
int n
);
long abs(
long n
); // C++ only
double abs(
double n
); // C++ only
long double abs(
long double n
); // C++ only
float abs(
float n
); // C++ only
__int64 _abs64(
__int64 n
);
Parameter
n
Integer value.
Return Value
The abs function returns the absolute value of its parameter. There is no error return.
Remarks
C++ allows overloading, so you can call overloads of abs. In a C program, abs always takes and returns an int.
int main( void )
{
int ix = -4, iy;
long lx = -41567L, ly;
double dx = -3.141593, dy;
__int64 wx = -1, wy;
wy = _abs64( wx );
printf( "The absolute value of %I64x is %I64x\n", wx, wy);
iy = abs( ix );
printf( "The absolute value of %d is %d\n", ix, iy);
ly = labs( lx );
printf( "The absolute value of %ld is %ld\n", lx, ly);
dy = fabs( dx );
printf( "The absolute value of %f is %f\n", dx, dy );
}
Output
The absolute value of ffffffffffffffff is 1
The absolute value of -4 is 4
The absolute value of -41567 is 41567
The absolute value of -3.141593 is 3.141593
See Also
Data Conversion Routines | Floating-Point Support | _cabs | fabs | labs | Run-Time Routines and .NET Framework Equivalents