C语言中正切的相关函数总结
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),即 双曲正切曲线示意图: 注意,使用 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |