首页 > 代码库 > 绝对值函数abs、fabs等的使用
绝对值函数abs、fabs等的使用
求数字的绝对值,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.
以上函数的原型说明来自MSDN2008,可以看出,ads()函数有很多重载形式。一般用ads()就可以满足要求(c++),其它的各种都是一些特例。double _cabs( struct _complex z );
不嫌麻烦的也可以采用模板的形式来重新定义。
绝对值函数abs、fabs等的使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。