Evaluate the absolute value of a number. Supported by library functions provided by VC ++, when it must include: # include <math. h>
There are several types: ABS, _ abs64, FABS, fabsf,Labs,_ Cabs. Details are as follows:
//Calculate the absolute value.
int abs( int n );long abs( long n ); // C++ onlydouble abs( double n ); // C++ onlylong double abs( long double n); // C++ onlyfloat abs( float n ); // C++ only__int64 _abs64( __int64 n );
//Calculates the absolute value of the floating-point argument.
double fabs( double x );float fabs( float x ); // C++ onlylong double fabs( long double x); // C++ onlyfloat fabsf( float x );
//Calculates the absolute value of a long integer.
long labs( long n );
//Calculates the absolute value of a complex number.
double _cabs( struct _complex z );
The prototype of the above function is from msdn2008. It can be seen that there are many overloaded functions in ads. Generally, ADS () can meet the requirements (C ++). Other cases are special cases.
You can also use a template to redefine it.
Use of absolute value functions abs and FABS