C语言中正切的相关函数总结
C语言中正切的相关函数总结
发布时间:2016-12-28 来源:查字典编辑
摘要:C语言tan()函数:正切函数头文件:#includetan()函数用来求给定值的正切值,其原型为:doubletan(doublex);【...

C语言tan()函数:正切函数

头文件:

#include <math.h>

tan() 函数用来求给定值的正切值,其原型为:

double tan(double x);

【参数】x 为给定的弧度值。

【返回值】返回 x 的正切值。

注意,使用 GCC 编译时请加入-lm。

请看下面的代码:

#include <math.h> main(){ double answer = tan(0.5); printf("tan(0.5) = %fn", answer); }

输出结果:

tan(0.5) = 0.546302

C语言tanh()函数:双曲线正切函数

头文件:

#include <math.h>

tanh() 用来求一个数的双曲正切值,其原型为:

double tanh(double x);

【参数】x 为双曲正切上的某点。

【返回值】返回 x 的双曲正切值,取值范围为 -1 到 1。

双曲正切的定义为 sinh(x)/cosh(x),即

C语言中正切的相关函数总结1

双曲正切曲线示意图:

C语言中正切的相关函数总结2

注意,使用 GCC 编译时请加入-lm。

请看下面的代码:

#include <math.h> main(){ double answer = tanh(0.5); printf("tanh(0.5) = %fn", answer); }

输出结果:

tanh(0.5) = 0.462117

C语言atan()函数:求反正切的值(以弧度表示)

头文件:

#include <math.h>

定义函数:

double atan(double x);

函数说明:atan()用来计算参数x 的反正切值,然后将结果返回。

返回值:返回-PI/2 至PI/2 之间的计算结果。

注意,使用 GCC 编译时请加入-lm。

范例

#include <math.h> main(){ double angle; angle = atan(1); printf("angle = %fn", angle); }

执行

angle = 1.570796

C语言atan2()函数:求反正切的值(以弧度表示)

头文件:

#include <math.h>

定义函数:

double atan2(double y, double x);

函数说明:atan2()用来计算参数y/x 的反正切值,然后将结果返回。

返回值:返回-PI/2 至PI/2 之间的计算结果。

注意,使用 GCC 编译时请加入-lm。

范例

#include <math.h> main(){ double angle; angle = atan2(1, 2); printf("angle = %fn", angle); }

执行

angle = 0.463648

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C语言学习
热门C语言学习
编程开发子分类