Math.cosh()

Math.cosh() 関数は、引数として与えた数の双曲線余弦 (ハイパーボリックコサイン) を返します。これは定数 e を使用して次のように表すことができます。

Math.cosh(x) = e x + e - x 2 \mathtt{\operatorname{Math.cosh(x)}} = \frac{e^x + e^{-x}}{2}

試してみましょう

構文

Math.cosh(x)

引数

x

数値。

返値

指定された数値の双曲線余弦 (ハイパーボリックコサイン) です。

解説

cosh()Math の静的メソッドであるため、生成した Math オブジェクトのメソッドとしてではなく、常に Math.cosh() として使用するようにしてください (Math はコンストラクターではありません)。

Math.cosh() の使用

js
Math.cosh(0); // 1
Math.cosh(1); // 1.5430806348152437
Math.cosh(-1); // 1.5430806348152437

ポリフィル

これは Math.exp() 関数を使用して次のようにエミュレートできます。

js
Math.cosh =
  Math.cosh ||
  function (x) {
    return (Math.exp(x) + Math.exp(-x)) / 2;
  };

または Math.exp() 関数を一度だけ呼び出すようにすると、次のようになります。

js
Math.cosh =
  Math.cosh ||
  function (x) {
    var y = Math.exp(x);
    return (y + 1 / y) / 2;
  };

仕様書

Specification
ECMAScript Language Specification
# sec-math.cosh

ブラウザーの互換性

BCD tables only load in the browser

関連情報