std::atanh, std::atanhf, std::atanhl

来自cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
 
在标头 <cmath> 定义
(1)
float       atanh (float num );

double      atanh (double num );

longdouble atanh (longdouble num );
(C++23 前)
/* 浮点数类型 */
            atanh (/* 浮点数类型 */ num );
(C++23 起)
(C++26 起 constexpr)
float       atanhf(float num );
(2) (C++11 起)
(C++26 起为 constexpr)
longdouble atanhl(longdouble num );
(3) (C++11 起)
(C++26 起为 constexpr)
SIMD 重载(C++26 起)
在标头 <simd> 定义
template</*math-floating-point*/ V >

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

            atanh (const V& v_num );
(S) (C++26 起)
额外重载(C++11 起)
在标头 <cmath> 定义
template<class Integer >
double      atanh ( Integer num );
(A) (C++26 起为 constexpr)
1-3) 计算 num 的反双曲正切。标准库提供所有以无 cv 限定的浮点数类型作为形参的类型的 std::atanh 重载。(C++23 起)
S) SIMD 重载对 v_num 实施逐元素 std::atanh
(参见 math-floating-pointdeduced-simd-t 的定义。)
(C++26 起)
A) 为所有整数类型提供额外重载,将它们当做 double
(C++11 起)

目录

[编辑]参数

num - 浮点数或整数

[编辑]返回值

如果没有发生错误,那么返回 num 的反双曲正切(tanh-1
(num)
artanh(num))。

如果发生定义域错误,那么返回值由实现定义(如果支持就是 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\n";}

可能的输出:

atanh(0) = 0 atanh(-0) = -0 atanh(0.9) = 1.47222 atanh(-1) = -inf errno == ERANGE: Numerical result out of range 发生 FE_DIVBYZERO

[编辑]参阅

(C++11)(C++11)(C++11)
计算反双曲正弦(arsinh(x)
(函数)[编辑]
(C++11)(C++11)(C++11)
计算反双曲余弦(arcosh(x)
(函数)[编辑]
(C++11)(C++11)
计算双曲正切(tanh(x)
(函数)[编辑]
计算复数的反双曲正切(artanh(z)
(函数模板)[编辑]
atanh 的 C 文档

[编辑]外部链接

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