Sinh
定义于头文件 <cmath>
中。
描述
计算 num
的双曲正弦。
该库为所有 cv-unqualified 浮点类型提供了 std::sinh 的重载,作为参数 num
的类型。 (自 C++23 起)
附加重载 为所有整数类型提供,它们被视为 double。 (自 C++11 起)
声明
- C++23
- C++11
// 1)
/* floating-point-type */ sinh( /* floating-point-type */ num );
// 2)
float sinhf( float num );
// 3)
long double sinhl( long double num );
// 4)
template< class Integer >
double sinh ( Integer num );
// 1)
float sinh ( float num );
// 2)
double sinh ( double num );
// 3)
long double sinh ( long double num );
// 4)
float sinhf( float num );
// 5)
long double sinhl( long double num );
// 6)
template< class Integer >
double sinh ( Integer num );
参数
num
- 浮点或整数值
返回值
如果没有发生错误,则返回 num
的双曲正弦 (sinh(num),或 (enum - e-num)/2)。如果发生溢出的范围错误,则返回 ±HUGE_VAL
、±HUGE_VALF
或 ±HUGE_VALL
。
如果因下溢导致范围错误,则返回正确结果(舍入后)。
错误处理
错误按 math_errhandling 中指定的方式报告。
如果实现支持 IEEE 浮点运算(IEC 60559)
如果参数是 ±0
或 ±∞
,则原样返回;如果参数是 NaN,则返回 NaN。
备注
POSIX 指定在下溢情况下,num
被原样返回,如果不支持,则返回不大于 DBL_MIN
、FLT_MIN
和 LDBL_MIN
的实现定义值。
额外的重载不需要完全按照额外重载提供。它们只需要足以确保对于其整数类型的参数 num
,
std::sinh(num)
的效果与 std::sinh(static_cast<double>(num))
相同。
示例
#include <cerrno>
#include <cfenv>
#include <cmath>
#include <cstring>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
int main()
{
const double x = 42;
std::cout
<< "sinh(1) = "
<< std::sinh(1) << '\n'
<< "sinh(-1) = "
<< std::sinh(-1) << '\n'
<< "log(sinh("
<< x << ")+cosh(" << x << ")) = "
<< std::log(std::sinh(x) + std::cosh(x)) << '\n';
// special values
std::cout
<< "sinh(+0) = "
<< std::sinh(0.0) << '\n'
<< "sinh(-0) = "
<< std::sinh(-0.0) << '\n';
// error handling
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(42)+cosh(42)) = 42
sinh(+0) = 0
sinh(-0) = -0
sinh(710.5) = inf
errno == ERANGE: Numerical result out of range
FE_OVERFLOW raised