std::cosh(std::valarray)
來自 cppreference.com
定義於標頭檔案 <valarray> |
||
template< class T > valarray<T> cosh( const valarray<T>& va ); |
||
對於 va 中的每個元素,計算該元素的雙曲餘弦值。
目錄 |
[編輯] 引數
va | - | 要應用操作的值陣列 |
[編輯] 返回值
包含 va 中值的雙曲餘弦的值陣列。
[編輯] 注意
使用非限定函式(cosh)執行計算。如果此類函式不可用,則由於實參依賴查詢,將使用 std::cosh。
該函式可以使用與 std::valarray 不同的返回型別實現。在這種情況下,替換型別具有以下屬性:
- 提供 std::valarray 的所有 const 成員函式。
- std::valarray、std::slice_array、std::gslice_array、std::mask_array 和 std::indirect_array 可以由替換型別構造。
- 對於每個接受 const std::valarray<T>& (除了 begin() 和 end() 以外的函式)(C++11 起) 的函式,應新增接受替換型別的相同函式;
- 對於每個接受兩個 const std::valarray<T>& 引數的函式,應新增接受 const std::valarray<T>& 和替換型別任意組合的相同函式。
- 返回型別不會在最深層巢狀的引數型別之上增加超過兩個模板巢狀級別。
[編輯] 可能實現
template<class T> valarray<T> cosh(const valarray<T>& va) { valarray<T> other = va; for (T& i : other) i = cosh(i); return other; // proxy object may be returned } |
[編輯] 示例
執行此程式碼
#include <cmath> #include <iomanip> #include <iostream> #include <valarray> void show(const char* title, const std::valarray<float>& data) { const int w{9}; std::cout << std::setw(w) << title << " | "; for (float x : data) std::cout << std::setw(w) << x << " | "; std::cout << '\n'; } int main() { const std::valarray<float> x{.1, .2, .3, .4}; const auto sinh = std::sinh(x); const auto cosh = std::cosh(x); const auto z = (cosh * cosh) - (sinh * sinh); show("x", x); show("sinh(x)", sinh); show("cosh(x)", cosh); show("z", z); }
輸出
x | 0.1 | 0.2 | 0.3 | 0.4 | sinh(x) | 0.100167 | 0.201336 | 0.30452 | 0.410752 | cosh(x) | 1.005 | 1.02007 | 1.04534 | 1.08107 | z | 1 | 1 | 1 | 1 |
[編輯] 參閱
將函式 std::sinh 應用於 valarray 的每個元素 (函式模板) | |
將函式 std::tanh 應用於 valarray 的每個元素 (函式模板) | |
(C++11)(C++11) |
計算雙曲餘弦(cosh(x)) (函式) |
計算複數的雙曲餘弦 (cosh(z)) (函式模板) |