atan() 函数定义在 math.h 头文件中。它有助于返回给定数字的反正切值(以弧度表示)。
double atan(double x); #where x should be a double
atan() 函数接受一个参数,该参数的范围可以是负值到正值中的任意值。使用强制转换运算符,我们可以将类型显式转换为 double,以找到 int、float 或 long double 类型的 atan()。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 双精度浮点数值 | 任何从负到正的 double 值 | 必需 |
atan() 函数的返回值范围在 [-pi/2, +pi/2] 弧度之间。
| 输入 | 返回值 |
|---|---|
| x = [-1, +1] | [-pi/2, +pi/2] 弧度 |
| -1 > x 或 x > 1 | NaN (非数字) |
#include <stdio.h>
#include <math.h>
#define PI 3.141592654
int main()
{
double n = 1.0;
double output;
output = atan(n);
printf("The Inverse of tan(%.2f) is equal to %.2f in radians", n, output);
// Converting radians to degrees
output = (output * 180) / PI;
printf("\nThe Inverse of tan(%.2f) is equal to %.2f in degrees", n, output);
return 0;
}
输出
The Inverse of tan(1.00) is equal to 0.79 in radians The Inverse of tan(1.00) is equal to 45 in degrees
#include <stdio.h>
#include <math.h>
int main () {
double v, out, value;
v = 1.0;
value = 180.0 / PI;
out = atan (v) * value;
printf("The arc tangent of %lf is %lf degrees", v, out);
return(0);
}
输出
The arc tangent of 1.000000 is 45.000000 degrees