Atan
定义于头文件 <cmath>
中。
描述
计算 `num` 的反正切主值。标准库为所有 cv 非限定浮点类型提供了 `std::atan` 的重载,作为参数 `num` 的类型 (C++23 起)。
附加重载为所有整数类型提供,它们被视为 double (自 C++11 起).
声明
- C++23
- C++11
// 1)
/* floating-point-type */ atan( /* floating-point-type */ num );
// 2)
float atanf( float num );
// 3)
long double atanl( long double num );
// 4)
template< class Integer >
double atan ( Integer num );
// 1)
float atan ( float num );
// 2)
double atan ( double num );
// 3)
long double atan ( long double num );
// 4)
float atanf( float num );
// 5)
long double atanl( long double num );
// 6)
template< class Integer >
double atan ( Integer num );
参数
`num` - 浮点或整数值
返回值
如果未发生错误,则返回 `num` 的反正切值 (arctan(num)),范围为 `[-π/2, π/2]` 弧度。如果由于下溢而发生范围错误,则返回正确的结果(四舍五入后)。
错误处理
错误按 math_errhandling 中指定的方式报告。
如果实现支持 IEEE 浮点运算(IEC 60559)
如果参数为 `±0`,则返回未修改的值。如果参数为 `+∞`,则返回 `+π/2`。如果参数为 `-∞`,则返回 `-π/2`。如果参数为 NaN,则返回 NaN。
备注
POSIX 规定,当下溢时,`num` 返回未修改的值;如果不支持,则返回一个不大于 `DBL_MIN`、`FLT_MIN` 和 `LDBL_MIN` 的实现定义值。
不要求额外重载完全按照额外重载提供。它们只需足以确保对于整数类型的参数 `num`,`std::atan(num)` 与 `std::atan(static_cast<double>(num))` 具有相同的效果。
示例
#include <cmath>
#include <iostream>
int main()
{
std::cout
<< "atan(1) = "
<< atan(1) << '\n'
<< "4*atan(1) = "
<< 4 * atan(1) << '\n';
// special values
std::cout
<< "atan(Inf) = "
<< atan(INFINITY) << '\n'
<< "2*atan(Inf) = "
<< 2 * atan(INFINITY) << '\n'
<< "atan(-0.0) = "
<< atan(-0.0) << '\n'
<< "atan(+0.0) = "
<< 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