std::sinh(std::valarray)
來自 cppreference.com
定義於標頭檔案 <valarray> |
||
template< class T > valarray<T> sinh( const valarray<T>& va ); |
||
對於 va 中的每個元素,計算該值的雙曲正弦。
目錄 |
[編輯] 引數
va | - | 要應用操作的值陣列 |
[編輯] 返回值
包含 va 中值的雙曲正弦的值陣列。
[編輯] 注意
使用非限定函式(sinh)執行計算。如果此函式不可用,則由於依賴於引數的查詢,將使用 std::sinh。
該函式可以使用與 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> sinh(const valarray<T>& va) { valarray<T> other = va; for (T& i : other) i = sinh(i); return other; // proxy object may be returned } |
[編輯] 示例
執行此程式碼
#include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <valarray> template<typename T> void show(char const* title, const std::valarray<T>& va) { std::cout << title << " : " << std::right; for (T x : va) std::cout << std::fixed << x << ' '; std::cout << '\n'; } template<typename T> void sinh_for(std::valarray<T> const& z) { // Hyperbolic sine is sinh(z) = (eᶻ - e⁻ᶻ) / 2. const std::valarray<T> sinh_z{std::sinh(z)}; const std::valarray<T> e_z{std::exp(z)}; const std::valarray<T> e_neg_z{std::exp(-z)}; const std::valarray<T> sinh_def{(e_z - e_neg_z) / 2.0f}; show("n ", z); show("sinh(n) ", sinh_z); show("(eⁿ-e⁻ⁿ)/2", sinh_def); std::cout.put('\n'); } int main() { sinh_for(std::valarray<float>{-.2f, -.1f, 0.f, .1f, .2f, INFINITY}); sinh_for(std::valarray<std::complex<double>>{{-.2,-.1}, {.2,.1}}); }
輸出
n : -0.200000 -0.100000 0.000000 0.100000 0.200000 inf sinh(n) : -0.201336 -0.100167 0.000000 0.100167 0.201336 inf (eⁿ-e⁻ⁿ)/2 : -0.201336 -0.100167 0.000000 0.100167 0.201336 inf n : (-0.200000,-0.100000) (0.200000,0.100000) sinh(n) : (-0.200330,-0.101837) (0.200330,0.101837) (eⁿ-e⁻ⁿ)/2 : (-0.200330,-0.101837) (0.200330,0.101837)
[編輯] 參閱
將函式 std::cosh 應用於 valarray 的每個元素 (函式模板) | |
將函式 std::tanh 應用於 valarray 的每個元素 (函式模板) | |
(C++11)(C++11) |
計算雙曲正弦(sinh(x)) (函式) |
計算複數的雙曲正弦 (sinh(z)) (函式模板) |