C++ 参考手册

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

定义于头文件 <cmath>
(1)
float       sinh ( float arg );
float       sinhf( float arg );
(C++11 起)
double      sinh ( double arg );
(2)
(3)
long double sinh ( long double arg );
long double sinhl( long double arg );
(C++11 起)
double      sinh ( IntegralType arg );
(4) (C++11 起)
1-3) 计算 arg 的双曲正弦。
4) 接受任何整数类型参数的重载集或函数模板。等价于 2) (将参数转型为 double )。

参数

arg - 浮点或整数类型

返回值

若不出现错误,则返回 arg 的双曲正弦( sinh(arg)
earg
-e-arg
2
)。

若出现上溢所致的值域错误,则返回 ±HUGE_VAL±HUGE_VALF±HUGE_VALL

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

错误处理

报告 math_errhandling 中指定的错误。

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

  • 若参数为 ±0 或 ±∞ ,则返回不修改的参数
  • 若参数为 NaN ,则返回 NaN

注意

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

示例

#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
 
#pragma STDC FENV_ACCESS ON
int main()
{
    std::cout << "sinh(1) = " << std::sinh(1) << '\n'
              << "sinh(-1) = " << std::sinh(-1) << '\n'
              << "log(sinh(1)+cosh(1)) = "
              << std::log(std::sinh(1)+std::cosh(1)) << '\n';
    // 特殊值
    std::cout << "sinh(+0) = " << std::sinh(0.0) << '\n'
              << "sinh(-0) = " << std::sinh(-0.0) << '\n';
    // 错误处理
    errno = 0;
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "sinh(710.5) = " << std::sinh(710.5) << '\n';
    if (errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if (std::fetestexcept(FE_OVERFLOW))
        std::cout << "    FE_OVERFLOW raised\n";
}

输出:

sinh(1) = 1.1752
sinh(-1) = -1.1752
log(sinh(1)+cosh(1)) = 1
sinh(+0) = 0
sinh(-0) = -0
sinh(710.5) = inf
    errno == ERANGE: Numerical result out of range
    FE_OVERFLOW raised

参阅

(C++11)(C++11)
计算双曲余弦( cosh(x)
(函数)
(C++11)(C++11)
计算双曲正切( tanh(x)
(函数)
(C++11)(C++11)(C++11)
计算反双曲正弦( arsinh(x)
(函数)
计算复数的双曲正弦( sinh(z)
(函数模板)
在 valarray 的每个元素上调用 std::sinh 函数
(函数模板)