Namespaces
Variants

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

From ja.cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
ヘッダー <cmath> で定義
(1)
float cosh(float num);

double cosh(double num);

long double cosh(long double num);
(C++23まで)
/*floating-point-type*/
cosh(/*floating-point-type*/ num);
(C++23から)
(constexpr since C++26)
float coshf(float num);
(2) (C++11から)
(constexpr since C++26)
long double coshl(long double num);
(3) (C++11から)
(constexpr since C++26)
SIMD overload (C++26から)
ヘッダー <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) (constexpr since C++26)
1-3) num の双曲線余弦を計算する。 ライブラリは、パラメータの型としてすべてのcv修飾されていない浮動小数点型について std::cosh のオーバーロードを提供する。 (C++23以降)
S) SIMDオーバーロードは v_num に対して要素ごとに std::cosh を実行します。
(詳細は math-floating-point および deduced-simd-t を参照)
(C++26以降)
A) すべての整数型に対して追加のオーバーロードが提供されており、これらは double として扱われます。
(C++11以降)

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - HTMLタグ、属性、、
、タグ内のテキストは翻訳していません
- C++固有の用語(Parameters、Return value、Error handling、Notes、Example、See also)は原文のまま保持しています
- 元のフォーマットと構造を完全に保持しています

パラメータ

num - 浮動小数点または整数値

戻り値

If no errors occur, the hyperbolic cosine of num ( cosh(num) , or
e num
+e -num
2
) is returned.

オーバーフローによる範囲エラーが発生した場合、 +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';
    // 特殊な値
    std::cout << "cosh(+0) = " << std::cosh(0.0) << '\n'
              << "cosh(-0) = " << std::cosh(-0.0) << '\n';
    // エラー処理
    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: 数値結果が範囲外です
    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) )
(関数テンプレート)
関数 std::cosh をvalarrayの各要素に適用する
(関数テンプレート)