跳到主要内容

C++ atan() 反正切函数

这个函数定义在 <cmath> 头文件中。

[数学] tan^-1x = atan(x) [在 C++ 编程中];

atan() 原型 [C++ 11 标准起]

double atan(double x);
float atan(float x);
long double atan(long double x);
double atan (T x); // 对于整数类型

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 << " 弧度" << endl;

// 输出为度数
cout << "atan(x) = " << result*180/3.1415 << " 度" << endl;

return 0;
}

当你运行程序时,输出将是:

atan(x) = 1.55348 弧度
atan(x) = 89.0104

示例 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 << " 弧度" << endl;
// 输出为度数
cout << "atan(x) = " << result*180/3.1415 << " 度" << endl;

return 0;
}

当你运行程序时,输出将是:

atan(x) = 1.49949 弧度
atan(x) = 85.9169