码迷,mamicode.com
首页 > 其他好文 > 详细

绝对值函数abs、fabs等的使用

时间:2014-08-29 11:01:47      阅读:245      评论:0      收藏:0      [点我收藏+]

标签: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.

double _cabs( 
   struct _complex z 
);

以上函数的原型说明来自MSDN2008,可以看出,ads()函数有很多重载形式。一般用ads()就可以满足要求(c++),其它的各种都是一些特例。
不嫌麻烦的也可以采用模板的形式来重新定义。

绝对值函数abs、fabs等的使用

标签:abs   fabs   绝对值   

原文地址:http://blog.csdn.net/cbnotes/article/details/38920921

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!