std::cosh, std::coshf, std::coshl
来自 cppreference.cn
| 定义于头文件 <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< /*数学浮点类型*/ V > constexpr /*推导 SIMD 类型*/<V> |
(S) | (C++26 起) |
| 额外重载 (自 C++11 起) |
||
| 定义于头文件 <cmath> |
||
template< class Integer > double cosh ( Integer num ); |
(A) | (C++26 起为 constexpr) |
1-3) 计算 num 的双曲余弦。库为所有 cv-unqualified 浮点类型的参数提供了
std::cosh 的重载。(C++23 起)|
S) SIMD 重载对 v_num 执行逐元素的
std::cosh。
|
(C++26 起) |
|
A) 为所有整数类型提供了额外的重载,它们被视为 double。
|
(C++11 起) |
目录 |
[编辑] 参数
| num | - | 浮点值或整数值 |
[编辑] 返回值
如果未发生错误,则返回 num 的双曲余弦(cosh(num),或| enum +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'; // special values std::cout << "cosh(+0) = " << std::cosh(0.0) << '\n' << "cosh(-0) = " << std::cosh(-0.0) << '\n'; // error handling 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: Numerical result out of range
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
| |