C++ 参考手册

位置:首页 > C++ 参考手册 >数值库 >常用数学函数 > std::atanh, std::atanh, std::atanhl

定义于头文件 <cmath>
float       atanh ( float arg );
float       atanhf( float arg );
(1) (C++11 起)
double      atanh ( double arg );
(2) (C++11 起)
long double atanh ( long double arg );
long double atanhl( long double arg );
(3) (C++11 起)
double      atanh ( IntegralType arg );
(4) (C++11 起)
1-3) 计算 arg 的反正切。
4) 接受任何整数类型参数的重载集或函数模板。等价于 2) (将参数转型到 double )。

参数

arg - 浮点或整数类型

返回值

若不出现错误,则返回 arg 的反双曲正切( tanh-1
(arg)
artanh(arg) )。

若出现定义域错误,则返回实现定义值(若支持则为 NaN )。

若出现极点错误,则返回 ±HUGE_VAL±HUGE_VALF±HUGE_VALL (带正确符号)。

若出现下溢所致的值域错误,则返回(舍入后的)正确结果。

错误处理

报告 math_errhandling 中指定的错误。

若参数不在区间 [-1, +1] 中,则出现值域错误。

若参数为 ±1 ,则出现极点错误。

若实现支持 IEEE 浮点算术( IEC 60559 ),则

  • 若参数为 ±0 ,则返回不修改的参数。
  • 若参数为 ±1 ,则返回 ±∞ 并引发 FE_DIVBYZERO
  • |arg|>1 ,则返回 NaN 并引发 FE_INVALID
  • 若参数为 NaN ,则返回 NaN 。

注意

尽管( C++ 对此函数引用的) C 标准命名此函数为“弧双曲正切”,双曲函数的反函数是面积函数。其参数为双曲扇形的面积,而非弧。正确的名称为“反双曲正切”( POSIX 所用)或“面积双曲正切”。

POSIX 指定在下溢的情况下,返回不修改的 arg ,而且若不支持,则返回不大于 DBL_MIN 、 FLT_MIN 和 LDBL_MIN 的值。

示例

#include <iostream>
#include <cmath>
#include <cfloat>
#include <cerrno>
#include <cfenv>
#include <cstring>
#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: Numerical result out of range
    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)
(函数)
计算复数的反双曲正切( artanh(z)
(函数模板)

外部链接

Weisstein, Eric W. “反双曲正切。”来自 MathWorld--A Wolfram Web Resource 。