名稱空間
變體
操作

std::sinh(std::valarray)

來自 cppreference.com
< cpp‎ | numeric‎ | valarray
 
 
 
 
定義於標頭檔案 <valarray>
template< class T >
valarray<T> sinh( const valarray<T>& va );

對於 va 中的每個元素,計算該值的雙曲正弦。

目錄

[編輯] 引數

va - 要應用操作的值陣列

[編輯] 返回值

包含 va 中值的雙曲正弦的值陣列。

[編輯] 注意

使用非限定函式(sinh)執行計算。如果此函式不可用,則由於依賴於引數的查詢,將使用 std::sinh

該函式可以使用與 std::valarray 不同的返回型別實現。在這種情況下,替換型別具有以下屬性:

[編輯] 可能的實現

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))
(函式模板) [編輯]