跳到主要内容

Atanh

定义于头文件 <cmath> 中。

描述

计算 num 的反双曲正切。 该库为所有 cv-unqualified 浮点类型提供了 std::atanh 的重载,作为参数 num 的类型 (C++23 起)

为所有整数类型提供了额外的重载,它们被视为 double

声明

// 1)
/* floating-point-type */ atanh( /* floating-point-type */ num );
// 2)
float atanhf( float num );
// 3)
long double atanhl( long double num );
附加重载
// 4)
template< class Integer >
double atanh ( Integer num );

参数

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_MINFLT_MINLDBL_MIN 的实现定义值。

额外的重载不需要完全按照额外重载提供。它们只需要足以确保对于其整数类型的参数 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';

// error handling
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

Atanh

定义于头文件 <cmath> 中。

描述

计算 num 的反双曲正切。 该库为所有 cv-unqualified 浮点类型提供了 std::atanh 的重载,作为参数 num 的类型 (C++23 起)

为所有整数类型提供了额外的重载,它们被视为 double

声明

// 1)
/* floating-point-type */ atanh( /* floating-point-type */ num );
// 2)
float atanhf( float num );
// 3)
long double atanhl( long double num );
附加重载
// 4)
template< class Integer >
double atanh ( Integer num );

参数

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_MINFLT_MINLDBL_MIN 的实现定义值。

额外的重载不需要完全按照额外重载提供。它们只需要足以确保对于其整数类型的参数 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';

// error handling
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