C语言tan()函数:正切函数
头文件:
| 1 |
#include <math.h>
|
tan() 函数用来求给定值的正切值,其原型为:
?| 1 |
double tan(double x);
|
【参数】x 为给定的弧度值。
【返回值】返回 x 的正切值。
注意,使用 GCC 编译时请加入-lm。
请看下面的代码:
?| 1 2 3 4 5 |
#include <math.h>
main(){
double answer = tan(0.5);
printf("tan(0.5) = %f\n", answer);
}
|
输出结果:
?| 1 |
tan(0.5) = 0.546302
|
C语言tanh()函数:双曲线正切函数
头文件:
| 1 |
#include <math.h>
|
tanh() 用来求一个数的双曲正切值,其原型为:
?| 1 |
double tanh(double x);
|
【参数】x 为双曲正切上的某点。
【返回值】返回 x 的双曲正切值,取值范围为 -1 到 1。
双曲正切的定义为 sinh(x)/cosh(x),即

双曲正切曲线示意图:

注意,使用 GCC 编译时请加入-lm。
请看下面的代码:
?| 1 2 3 4 5 |
#include <math.h>
main(){
double answer = tanh(0.5);
printf("tanh(0.5) = %f\n", answer);
}
|
输出结果:
?| 1 |
tanh(0.5) = 0.462117
|
C语言atan()函数:求反正切的值(以弧度表示)
头文件:
| 1 |
#include <math.h>
|
定义函数:
?| 1 |
double atan(double x);
|
函数说明:atan()用来计算参数x 的反正切值,然后将结果返回。
返回值:返回-PI/2 至PI/2 之间的计算结果。
注意,使用 GCC 编译时请加入-lm。
范例
?| 1 2 3 4 5 6 |
#include <math.h>
main(){
double angle;
angle = atan(1);
printf("angle = %f\n", angle);
}
|
执行
?| 1 |
angle = 1.570796
|
C语言atan2()函数:求反正切的值(以弧度表示)
头文件:
| 1 |
#include <math.h>
|
定义函数:
?| 1 |
double atan2(double y, double x);
|
函数说明:atan2()用来计算参数y/x 的反正切值,然后将结果返回。
返回值:返回-PI/2 至PI/2 之间的计算结果。
注意,使用 GCC 编译时请加入-lm。
范例
?| 1 2 3 4 5 6 |
#include <math.h>
main(){
double angle;
angle = atan2(1, 2);
printf("angle = %f\n", angle);
}
|
执行
?| 1 |
angle = 0.463648
|








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。