Namespaces
Variants

std:: atan, std:: atanf, std:: atanl

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
定义于头文件 <cmath>
(1)
float atan ( float num ) ;

double atan ( double num ) ;

long double atan ( long double num ) ;
(C++23 前)
/*floating-point-type*/
atan ( /*floating-point-type*/ num ) ;
(C++23 起)
(C++26 起为 constexpr)
float atanf ( float num ) ;
(2) (C++11 起)
(C++26 起为 constexpr)
long double atanl ( long double num ) ;
(3) (C++11 起)
(C++26 起为 constexpr)
SIMD 重载 (C++26 起)
定义于头文件 <simd>
template < /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/ < V >

atan ( const V & v_num ) ;
(S) (C++26 起)
附加重载 (C++11 起)
定义于头文件 <cmath>
template < class Integer >
double atan ( Integer num ) ;
(A) (C++26 起为 constexpr)
1-3) 计算 num 的反正切主值。 标准库为所有 cv 未限定浮点类型提供了 std::atan 的重载版本作为参数类型。 (since C++23)
S) SIMD重载对 v_num 执行逐元素的 std::atan 运算。
(参见 math-floating-point deduced-simd-t 了解其定义。)
(since C++26)
A) 为所有整数类型提供了额外的重载,这些类型被视为 double
(since C++11)

目录

参数

num - 浮点数或整数值

返回值

If no errors occur, the arc tangent of num ( arctan(num) ) in the range [-
π
2
, +
π
2
]
radians, is returned.

如果由于下溢发生范围错误,将返回正确结果(舍入后)。

错误处理

错误报告方式遵循 math_errhandling 中的规范。

如果实现支持 IEEE 浮点算术 (IEC 60559),

  • 若参数为 ±0,则不作修改直接返回。
  • 若参数为 +∞,则返回 +π/2。
  • 若参数为 -∞,则返回 -π/2。
  • 若参数为 NaN,则返回 NaN。

注释

POSIX 规范 规定,在下溢情况下,将返回未修改的 num ;若不支持此行为,则返回不大于 DBL_MIN FLT_MIN LDBL_MIN 的实现定义值。

额外的重载不需要完全按照 (A) 提供。它们只需确保对于整数类型的实参 num std :: atan ( num ) std :: atan ( static_cast < double > ( num ) ) 具有相同效果。

示例

#include <cmath>
#include <iostream>
int main()
{
    std::cout << "atan(1) = " << std::atan(1) << '\n'
              << "4*atan(1) = " << 4 * std::atan(1) << '\n';
    // 特殊值
    std::cout << "atan(Inf) = " << std::atan(INFINITY) << '\n'
              << "2*atan(Inf) = " << 2 * std::atan(INFINITY) << '\n'
              << "atan(-0.0) = " << std::atan(-0.0) << '\n'
              << "atan(+0.0) = " << std::atan(0) << '\n';
}

输出:

atan(1) = 0.785398
4*atan(1) = 3.14159
atan(Inf) = 1.5708
2*atan(Inf) = 3.14159
atan(-0.0) = -0
atan(+0.0) = 0

参见

(C++11) (C++11)
计算反正弦( arcsin(x)
(函数)
(C++11) (C++11)
计算反余弦( arccos(x)
(函数)
(C++11) (C++11)
使用符号确定象限的反正切
(函数)
(C++11) (C++11)
计算正切( tan(x)
(函数)
计算复数的反正切( arctan(z)
(函数模板)
对 valarray 的每个元素应用函数 std::atan
(函数模板)
C 文档 关于 atan