Namespaces
Variants

std:: acosh, std:: acoshf, std:: acoshl

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
定义于头文件 <cmath>
(1)
float acosh ( float num ) ;

double acosh ( double num ) ;

long double acosh ( long double num ) ;
(C++23 前)
/*floating-point-type*/
acosh ( /*floating-point-type*/ num ) ;
(C++23 起)
(C++26 起为 constexpr)
float acoshf ( float num ) ;
(2) (C++11 起)
(C++26 起为 constexpr)
long double acoshl ( long double num ) ;
(3) (C++11 起)
(C++26 起为 constexpr)
SIMD 重载 (C++26 起)
定义于头文件 <simd>
template < /*math-floating-point*/ V >

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

acosh ( const V & v_num ) ;
(S) (C++26 起)
附加重载 (C++11 起)
定义于头文件 <cmath>
template < class Integer >
double acosh ( Integer num ) ;
(A) (C++26 起为 constexpr)
1-3) 计算 num 的反双曲余弦值。 库为所有 cv 未限定浮点类型提供了 std::acosh 的重载版本作为参数类型。 (C++23 起)
S) SIMD 重载对 v_num 执行逐元素的 std::acosh 运算。
(定义参见 math-floating-point deduced-simd-t
(since C++26)
A) 为所有整数类型提供了额外的重载,这些类型被视为 double
(since C++11)

目录

参数

num - 浮点数或整数值

返回值

若无错误发生,则返回 num 的反双曲余弦值( cosh -1
(num)
,即 arcosh(num) ),其定义域为 [0, +∞]

如果发生定义域错误,则返回一个由实现定义的值(在支持 NaN 的情况下返回 NaN)。

错误处理

错误报告方式遵循 math_errhandling 中的规范。

如果参数小于1,将发生定义域错误。

如果实现支持 IEEE 浮点算术 (IEC 60559),

  • 若参数小于1,则引发 FE_INVALID 并返回 NaN。
  • 若参数为1,则返回 +0。
  • 若参数为 +∞,则返回 +∞。
  • 若参数为 NaN,则返回 NaN。

注释

尽管C标准(C++在此函数上引用该标准)将此函数命名为“反双曲余弦”,但双曲函数的反函数实际上是面积函数。它们的参数是双曲扇形的面积,而非弧长。正确的名称应为“反双曲余弦”(POSIX使用)或“面积双曲余弦”。

额外的重载并不要求完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num std :: 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';
    // 错误处理
    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

参阅

(C++11) (C++11) (C++11)
计算反双曲正弦( arsinh(x)
(函数)
(C++11) (C++11) (C++11)
计算反双曲正切( artanh(x)
(函数)
(C++11) (C++11)
计算双曲余弦( cosh(x)
(函数)
计算复数的反双曲余弦( arcosh(z)
(函数模板)
C 文档 for acosh

外部链接

魏斯坦, 埃里克·W。《反双曲余弦》。 摘自 MathWorld —— 一个 Wolfram 网络资源。