📜  C++ STL-math.atan()函数(1)

📅  最后修改于: 2023-12-03 14:39:51.130000             🧑  作者: Mango

C++ STL - math.atan()函数

简介

math.atan()函数是C++ STL的一个数学函数,用于计算反正切值。

函数声明
double atan(double x);
参数
  • x:一个double类型的参数,表示需要计算反正切的值。
返回值
  • 返回一个double类型的值,表示计算结果的反正切值。
示例代码
计算反正切值
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double x = 1.0;
    cout << "反正切值:" << atan(x) << endl;
    return 0;
}

输出结果:

反正切值:0.785398
使用反正切函数计算角度
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double x = 1.0;
    double angle = atan(x) * 180 / M_PI;
    cout << "角度:" << angle << endl;
    return 0;
}

输出结果:

角度:45
注意事项
  • 函数返回值的单位为弧度,需根据需要进行角度转换。
  • 当参数x为正数时,反正切值在0到π/2之间;当参数x为负数时,反正切值在-π/2到0之间。