求绝对值函数abs()到底应该包含哪个头文件

来源:互联网 发布:淘宝商家运作流程图 编辑:程序博客网 时间:2024/05/17 07:23

C/C++语言的标准库里包含求绝对值的函数abs(),可是它到底是在哪个头文件里面声明的呢?


C语言中,

求整数的绝对值abs()和labs()应该包含stdlib.h

求浮点数的绝对值fabs()应该包含math.h


在C++中,只需要包括cmath即可。


参考网站:http://www.cplusplus.com/reference


C标准:

只在stdlib.h中有定义abs():

int abs (int n);

C++标准:

在stdlib.h中

     int abs (     int n);long int abs (long int n);

在math.h中

     double abs (double x);      float abs (float x);long double abs (long double x);