std::cosh, std::coshf, std::coshl
來自 cppreference.com
定義於標頭檔案 <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
|