跳到主要内容

Acosh

定义于头文件 <cmath> 中。

描述

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

附加重载 为所有整数类型提供,它们被视为 double

声明

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

参数

num - 浮点或整数值

返回值

如果没有发生错误,返回 num 在区间 [0, +∞] 上的反双曲余弦(cosh-1(num) 或 arcosh(num))。

如果发生域错误,则返回实现定义的值(如果支持,返回 NaN)。

错误处理

错误按 math_errhandling 中指定的方式报告。

如果参数小于 1,则发生域错误。

如果实现支持 IEEE 浮点运算(IEC 60559

如果参数小于 1,则引发 FE_INVALID 并返回 NaN
如果参数是 1,则返回 +0
如果参数是 +∞,则返回 +∞
如果参数是 NaN,则返回 NaN

备注

尽管 C 标准(C++ 参照此函数)将此函数命名为“反双曲余弦”,但双曲函数的反函数是面积函数。它们的参数是双曲扇形的面积,而不是弧。正确的名称是“反双曲余弦”(POSIX 使用)或“面积双曲余弦”。

不需要严格按照 附加重载 提供额外的重载。它们只需要足以确保对于整数类型的参数 numstd::acosh(num) 具有与 std::acosh(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
<< "acosh(1) = "
<< std::acosh(1) << '\n'
<< "acosh(10) = "
<< std::acosh(10) << '\n'
<< "acosh(DBL_MAX) = "
<< std::acosh(DBL_MAX) << '\n'
<< "acosh(Inf) = "
<< std::acosh(INFINITY) << '\n';

// error handling
errno = 0;
std::feclearexcept(FE_ALL_EXCEPT);

std::cout
<< "acosh(0.5) = "
<< std::acosh(0.5) << '\n';

if (errno == EDOM)
std::cout
<< "errno == EDOM: "
<< std::strerror(errno) << '\n';
if (std::fetestexcept(FE_INVALID))
std::cout
<< "FE_INVALID raised\n";
}
可能结果
acosh(1) = 0
acosh(10) = 2.99322
acosh(DBL_MAX) = 710.476
acosh(Inf) = inf
acosh(0.5) = -nan
errno == EDOM: Numerical argument out of domain
FE_INVALID raised

Acosh

定义于头文件 <cmath> 中。

描述

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

附加重载 为所有整数类型提供,它们被视为 double

声明

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

参数

num - 浮点或整数值

返回值

如果没有发生错误,返回 num 在区间 [0, +∞] 上的反双曲余弦(cosh-1(num) 或 arcosh(num))。

如果发生域错误,则返回实现定义的值(如果支持,返回 NaN)。

错误处理

错误按 math_errhandling 中指定的方式报告。

如果参数小于 1,则发生域错误。

如果实现支持 IEEE 浮点运算(IEC 60559

如果参数小于 1,则引发 FE_INVALID 并返回 NaN
如果参数是 1,则返回 +0
如果参数是 +∞,则返回 +∞
如果参数是 NaN,则返回 NaN

备注

尽管 C 标准(C++ 参照此函数)将此函数命名为“反双曲余弦”,但双曲函数的反函数是面积函数。它们的参数是双曲扇形的面积,而不是弧。正确的名称是“反双曲余弦”(POSIX 使用)或“面积双曲余弦”。

不需要严格按照 附加重载 提供额外的重载。它们只需要足以确保对于整数类型的参数 numstd::acosh(num) 具有与 std::acosh(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
<< "acosh(1) = "
<< std::acosh(1) << '\n'
<< "acosh(10) = "
<< std::acosh(10) << '\n'
<< "acosh(DBL_MAX) = "
<< std::acosh(DBL_MAX) << '\n'
<< "acosh(Inf) = "
<< std::acosh(INFINITY) << '\n';

// error handling
errno = 0;
std::feclearexcept(FE_ALL_EXCEPT);

std::cout
<< "acosh(0.5) = "
<< std::acosh(0.5) << '\n';

if (errno == EDOM)
std::cout
<< "errno == EDOM: "
<< std::strerror(errno) << '\n';
if (std::fetestexcept(FE_INVALID))
std::cout
<< "FE_INVALID raised\n";
}
可能结果
acosh(1) = 0
acosh(10) = 2.99322
acosh(DBL_MAX) = 710.476
acosh(Inf) = inf
acosh(0.5) = -nan
errno == EDOM: Numerical argument out of domain
FE_INVALID raised