std::cosh, std::coshf, std::coshl
来自cppreference.com
数值库
常用数学函数
| 函数 | |||||||||||||||||||||
| 基本运算 | |||||||||||||||||||||
|
|||||||||||||||||||||
| 指数函数 | |||||||||||||||||||||
| 幂函数 | |||||||||||||||||||||
| 三角与双曲函数 | |||||||||||||||||||||
| 误差与伽马函数 | |||||||||||||||||||||||||||||||||||||||||
| 临近整数的浮点运算 | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 浮点操作函数 | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 分类/比较 | |||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
| 宏常量 | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
在标头
<cmath>
定义
|
||
| (1) | ||
|
float cosh
( float num );
double cosh (
double num ); |
(C++23 前) | |
|
/* 浮点类型 */
cosh( /* 浮点类型 */ num
);
|
(C++23 起) | |
|
float
coshf( float num );
|
(2) | (C++11 起) |
|
long double coshl( long double num );
|
(3) | (C++11 起) |
|
额外重载 (C++11 起)
|
||
|
在标头
<cmath>
定义
|
||
|
template< class Integer >
double cosh ( Integer num ); |
(A) | |
1-3) 计算 num 的双曲余弦。标准库提供所有以无 cv 限定的浮点类型作为参数 num 的类型的
std::cosh
重载。 (C++23 起)
|
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() { std::cout << "cosh(1) = " << std::cosh(1) << '\n' << "cosh(-1) = " << std::cosh(-1) << '\n' << "log(sinh(1)+cosh(1)=" << std::log(std::sinh(1) + std::cosh(1)) << '\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\n"; }
可能的输出:
cosh(1) = 1.54308
cosh(-1) = 1.54308
log(sinh(1)+cosh(1)=1
cosh(+0) = 1
cosh(-0) = 1
cosh(710.5) = inf
errno == ERANGE: Numerical result out of range
发生 FE_OVERFLOW
参阅
|
(C++11)(C++11)
|
计算双曲正弦(\({\small\sinh{x} }\)sinh(x)) (函数) |
|
(C++11)(C++11)
|
计算双曲正切(\({\small\tanh{x} }\)tanh(x)) (函数) |
|
(C++11)(C++11)(C++11)
|
计算反双曲余弦(\({\small\operatorname{arcosh}{x}
}\)arcosh(x)) (函数) |
| 计算复数的双曲余弦(\({\small\cosh{z} }\)cosh(z)) (函数模板) |
|
| 在 valarray 的每个元素上调用 std::cosh 函数 (函数模板) |