std::atan, std::atanf, std::atanl
来自cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
, +
]
| 在标头 <cmath> 定义
|
||
| (1) | ||
float atan ( float num ); double atan ( double num ); long double atan ( long double num ); |
(C++23 前) | |
/* 浮点数类型 */ atan ( /* 浮点数类型 */ 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 重载。(C++23 起)|
S) SIMD 重载对
v_num 实施逐元素 std::atan。
|
(C++26 起) |
|
A) 为所有整数类型提供额外重载,将它们当做
double。 |
(C++11 起) |
参数
| num | - | 浮点数或整数 |
返回值
如果没有发生错误,那么返回 num 在
| π |
| 2 |
| π |
| 2 |
弧度范围中的弧(反)正切(arctan(num))。
如果发生下溢所致的值域错误,那么返回(舍入后的)正确结果。
错误处理
报告 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)) (函数) |
(C++11) |
计算复数的反正切(arctan(z)) (函数模板) |
| 应用函数 std::atan 到 valarray 的每个元素 (函数模板) | |
atan 的 C 文档
| |