名稱空間
變體
操作

std::cosh(std::valarray)

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

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

目錄

[編輯] 引數

va - 要應用操作的值陣列

[編輯] 返回值

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

[編輯] 注意

使用非限定函式(cosh)執行計算。如果此類函式不可用,則由於實參依賴查詢,將使用 std::cosh

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

[編輯] 可能實現

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