std::cosh, std::coshf, std::coshl
来自cppreference.com
| 定义于头文件 <cmath>
|
||
| (1) | ||
| float cosh ( float arg ); |
||
| float coshf( float arg ); |
(C++11 起) | |
| double cosh ( double arg ); |
(2) | |
| (3) | ||
| long double cosh ( long double arg ); |
||
| long double coshl( long double arg ); |
(C++11 起) | |
| double cosh ( IntegralType arg ); |
(4) | (C++11 起) |
1-3) 计算
arg 的双曲余弦。参数
| arg | - | 浮点或整数类型值 |
返回值
若不出现错误,则返回arg 的双曲余弦( cosh(arg) 或 | earg +e-arg |
| 2 |
若出现上溢所致的值域错误,则返回 +HUGE_VAL 、 +HUGE_VALF 或 +HUGE_VALL 。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点算术( IEC 60559 ),则
- 若参数为 ±0 ,则返回 1
- 若参数为 ±∞ ,则返回 +∞
- 若参数为 NaN ,则返回 NaN
注解
对于 IEEE 兼容的 double 类型,若 |arg| > 710.5 ,则 cosh(arg) 上溢。
示例
运行此代码
#include <iostream> #include <cmath> #include <cerrno> #include <cstring> #include <cfenv> #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 raised\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 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 函数 (函数模板) |