求數字的絕對值,vc++提供的庫函數的支援,當必須包含: #include <math.h>
其中又分好幾種類型:abs、_abs64、fabs、fabsf、labs、_cabs。詳細說明如下:
//Calculate 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
);
//Calculates the absolute value of the floating-point argument.
double fabs(
double x
);
float fabs(
float x
); // C++ only
long double fabs(
long double x
); // C++ only
float 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
);
以上函數的原型說明來自MSDN2008,可以看出,ads()函數有很多重載形式。一般用ads()就可以滿足要求(c++),其它的各種都是一些特例。
不嫌麻煩的也可以采用模闆的形式來重新定義。