此函数定义在 <cmath> 头文件中。
[Mathematics] tan-1x = atan(x) [In C++ Programming];
atan() 原型 [截至 C++ 11 标准]
double atan(double x); float atan(float x); long double atan(long double x); double atan (T x); // For integral type
atan() 参数
atan() 函数接受一个必需参数(可以是正数、负数或零)
atan() 返回值
atan() 函数返回 **[-π/2, π/2]** 范围内的值。
示例 1:atan() 的工作原理?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 57.74, result;
result = atan(x);
cout << "atan(x) = " << result << " radians" << endl;
// Output in degrees
cout << "atan(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}
运行程序后,输出将是
atan(x) = 1.55348 radians atan(x) = 89.0104 degrees
示例 2:带整数类型的 atan() 函数
#include <iostream>
#include <cmath>
#define PI 3.141592654
using namespace std;
int main()
{
int x = 14;
double result;
result = atan(x);
cout << "atan(x) = " << result << " radians" << endl;
// Output in degrees
cout << "atan(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}
运行程序后,输出将是
atan(x) = 1.49949 radians atan(x) = 85.9169 degrees
另请阅读