std:: atanh, std:: atanhf, std:: atanhl
|
定义于头文件
<cmath>
|
||
| (1) | ||
|
float
atanh
(
float
num
)
;
double
atanh
(
double
num
)
;
|
(C++23 前) | |
|
/*浮点类型*/
atanh ( /*浮点类型*/ num ) ; |
(C++23 起)
(C++26 起为 constexpr) |
|
|
float
atanhf
(
float
num
)
;
|
(2) |
(C++11 起)
(C++26 起为 constexpr) |
|
long
double
atanhl
(
long
double
num
)
;
|
(3) |
(C++11 起)
(C++26 起为 constexpr) |
|
SIMD 重载
(C++26 起)
|
||
|
定义于头文件
<simd>
|
||
|
template
<
/*数学浮点类型*/
V
>
constexpr
/*推导的 SIMD 类型*/
<
V
>
|
(S) | (C++26 起) |
|
额外重载
(C++11 起)
|
||
|
定义于头文件
<cmath>
|
||
|
template
<
class
Integer
>
double atanh ( Integer num ) ; |
(A) | (C++26 起为 constexpr) |
std::atanh
的重载版本作为参数类型。
(C++23 起)
|
S)
SIMD 重载对
v_num
执行逐元素的
std::atanh
运算。
|
(since C++26) |
|
A)
为所有整数类型提供了额外的重载,这些类型被视为
double
。
|
(since C++11) |
目录 |
参数
| num | - | 浮点数或整数值 |
返回值
若无错误发生,则返回
num
的反双曲正切值(
tanh
-1
(num)
,或
artanh(num)
)。
如果发生定义域错误,将返回一个由实现定义的值(在支持 NaN 的情况下返回 NaN)。
如果出现极点错误,将返回
±HUGE_VAL
、
±HUGE_VALF
或
±HUGE_VALL
(保留正确的符号)。
如果由于下溢发生范围错误,将返回正确结果(舍入后)。
错误处理
错误报告方式遵循 math_errhandling 中的规范。
如果参数不在区间
[
-
1
,
+
1
]
内,则会发生范围错误。
如果参数为 ±1,将出现极点错误。
如果实现支持 IEEE 浮点算术 (IEC 60559),
- 若参数为 ±0,则不作修改直接返回。
- 若参数为 ±1,则返回 ±∞ 并引发 FE_DIVBYZERO 。
- 若 |num|>1 ,则返回 NaN 并引发 FE_INVALID 。
- 若参数为 NaN,则返回 NaN。
注释
尽管C标准(C++在此函数上引用该标准)将此函数命名为“反双曲正切”,但双曲函数的反函数实际上是面积函数。它们的参数是双曲扇形的面积,而非弧长。正确的名称应为“反双曲正切”(POSIX使用)或“面积双曲正切”。
POSIX 规范 规定,在下溢情况下,将返回未修改的 num ;若不支持此行为,则返回不大于 DBL_MIN 、 FLT_MIN 和 LDBL_MIN 的实现定义值。
额外的重载并不要求完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num , std :: atanh ( num ) 能够产生与 std :: atanh ( static_cast < double > ( num ) ) 相同的效果即可。
示例
#include <cerrno> #include <cfenv> #include <cfloat> #include <cmath> #include <cstring> #include <iostream> // #pragma STDC FENV_ACCESS ON int main() { std::cout << "atanh(0) = " << std::atanh(0) << '\n' << "atanh(-0) = " << std::atanh(-0.0) << '\n' << "atanh(0.9) = " << std::atanh(0.9) << '\n'; // 错误处理 errno = 0; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "atanh(-1) = " << std::atanh(-1) << '\n'; if (errno == ERANGE) std::cout << " errno == ERANGE: " << std::strerror(errno) << '\n'; if (std::fetestexcept(FE_DIVBYZERO)) std::cout << " FE_DIVBYZERO raised\n"; }
可能的输出:
atanh(0) = 0
atanh(-0) = -0
atanh(0.9) = 1.47222
atanh(-1) = -inf
errno == ERANGE: 数值结果超出范围
FE_DIVBYZERO raised
参见
|
(C++11)
(C++11)
(C++11)
|
计算反双曲正弦(
arsinh(x)
)
(函数) |
|
(C++11)
(C++11)
(C++11)
|
计算反双曲余弦(
arcosh(x)
)
(函数) |
|
(C++11)
(C++11)
|
计算双曲正切(
tanh(x)
)
(函数) |
|
(C++11)
|
计算复数的反双曲正切(
artanh(z)
)
(函数模板) |
|
C 文档
for
atanh
|
|
外部链接
| 韦斯坦,埃里克·W。《反双曲正切函数》 摘自 MathWorld —— 一个 Wolfram 网络资源。 |