std:: cosh, std:: coshf, std:: coshl
|
定义于头文件
<cmath>
|
||
| (1) | ||
|
float
cosh
(
float
num
)
;
double
cosh
(
double
num
)
;
|
(C++23 前) | |
|
/*floating-point-type*/
cosh ( /*floating-point-type*/ num ) ; |
(C++23 起)
(C++26 起为 constexpr) |
|
|
float
coshf
(
float
num
)
;
|
(2) |
(C++11 起)
(C++26 起为 constexpr) |
|
long
double
coshl
(
long
double
num
)
;
|
(3) |
(C++11 起)
(C++26 起为 constexpr) |
|
SIMD 重载
(C++26 起)
|
||
|
定义于头文件
<simd>
|
||
|
template
<
/*math-floating-point*/
V
>
constexpr
/*deduced-simd-t*/
<
V
>
|
(S) | (C++26 起) |
|
附加重载
(C++11 起)
|
||
|
定义于头文件
<cmath>
|
||
|
template
<
class
Integer
>
double cosh ( Integer num ) ; |
(A) | (C++26 起为 constexpr) |
std::cosh
的重载,作为参数类型。
(C++23 起)
|
S)
SIMD 重载对
v_num
执行逐元素的
std::cosh
运算。
|
(since C++26) |
|
A)
为所有整数类型提供了额外的重载,这些类型被视为
double
。
|
(since C++11) |
目录 |
参数
| num | - | 浮点数或整数值 |
返回值
If no errors occur, the hyperbolic cosine of num ( cosh(num) , or|
e
num
+e -num |
| 2 |
如果发生因溢出导致的范围错误,将返回
+HUGE_VAL
、
+HUGE_VALF
或
+HUGE_VALL
。
错误处理
错误报告方式遵循 math_errhandling 中的规范。
如果实现支持 IEEE 浮点算术 (IEC 60559),
- 若参数为 ±0,则返回 1。
- 若参数为 ±∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
注释
对于 IEEE 兼容的 double 类型,若 |num| > 710.5 ,则 std :: cosh ( num ) 会产生溢出。
额外的重载不需要完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num , std :: cosh ( num ) 与 std :: cosh ( 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 << "cosh(1) = " << std::cosh(1) << '\n' << "cosh(-1) = " << std::cosh(-1) << '\n' << "log(sinh(" << x << ")+cosh(" << x << ")) = " << std::log(std::sinh(x) + std::cosh(x)) << '\n'; // 特殊值 std::cout << "cosh(+0) = " << std::cosh(0.0) << '\n' << "cosh(-0) = " << std::cosh(-0.0) << '\n'; // 错误处理 errno=0; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "cosh(710.5) = " << std::cosh(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"; }
可能的输出:
cosh(1) = 1.54308
cosh(-1) = 1.54308
log(sinh(42)+cosh(42)) = 42
cosh(+0) = 1
cosh(-0) = 1
cosh(710.5) = inf
errno == ERANGE: 数值结果超出范围
FE_OVERFLOW raised
参见
|
(C++11)
(C++11)
|
计算双曲正弦 (
sinh(x)
)
(函数) |
|
(C++11)
(C++11)
|
计算双曲正切 (
tanh(x)
)
(函数) |
|
(C++11)
(C++11)
(C++11)
|
计算反双曲余弦 (
arcosh(x)
)
(函数) |
|
计算复数的双曲余弦 (
cosh(z)
)
(函数模板) |
|
|
对 valarray 的每个元素应用函数
std::cosh
(函数模板) |
|
|
C 文档
关于
cosh
|
|