名前空間
変種
操作

std::cosh, std::coshf, std::coshl

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
 
ヘッダー <cmath> で定義
(1)
float       cosh ( float num );

double      cosh ( double num );

long double cosh ( long double num );
(C++23まで)
/*浮動小数点数型*/
            cosh ( /*浮動小数点型*/ 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> で定義
template< /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/<V>

            cosh ( const V& v_num );
(S) (C++26以降)
ヘッダー <cmath> で定義
template< class Integer >
double      cosh ( Integer num );
(A) (C++26 以降 constexpr)
1-3) `num` の双曲線余弦を計算します。(C++23以降)パラメータの型として、すべての cv 修飾されていない浮動小数点型に対する `std::cosh` のオーバーロードが提供されます。
S) SIMD オーバーロードは、`v_num` に対して要素ごとの `std::cosh` を実行します。
(定義については、math-floating-point および deduced-simd-t を参照してください。)
(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` を適用します
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)