cos函数用法详解
cos函数简介
- 头文件包含
#include <math.h>
- 函数定义
double cos(double x );
float cosf(float x );
long double cosl(long double x );
- 编译链接选项
-lm
cos函数常见使用错误
- 链接错误
undefined reference to `cos'
解决办法:添加链接选项
-lm
- 编译错误
warning: implicit declaration of function ‘cos’ [-Wimplicit-function-declaration]
解决办法:包含头文件
#include <math.h>
cos函数详细描述
这些函数返回x 的余弦,其中x以弧度为单位。
cos函数返回值
成功后,这些函数返回x 的余弦
如果x是NaN,则返回NaN。
如果x是正无穷大或负无穷大,则发生域错误,并返回NaN。
cos函数错误码
有关如何确定调用这些函数时是否发生错误的信息,请参见math_error (7)。
可能出现以下错误:
- 域错误:x是无穷大,errno设置为EDOM(但请参见bug)。引发无效浮点异常( FE_INVALID )。
评论区