--- title: Math.tanh() slug: Web/JavaScript/Reference/Global_Objects/Math/tanh tags: - ECMAScript 2015 - JavaScript - Math - Method - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Math/tanh ---
{{JSRef}}

Math.tanh() 関数は、引数として与えた数のハイパーボリックタンジェントを返します。すなわち

tanhx=sinhxcoshx=ex-e-xex+e-x=e2x-1e2x+1\tanh x = \frac{\sinh x}{\cosh x} = \frac {e^x - e^{-x}} {e^x + e^{-x}} = \frac{e^{2x} - 1}{e^{2x}+1}

{{EmbedInteractiveExample("pages/js/math-tanh.html")}}

構文

Math.tanh(x)

引数

x
数値。

返値

指定された数値のハイパーボリックタンジェントです。

解説

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

ポリフィル

{{jsxref("Math.exp()")}} 関数の助けを借りて、エミュレートできます。:

Math.tanh = Math.tanh || function(x){
    var a = Math.exp(+x), b = Math.exp(-x);
    return a == Infinity ? 1 : b == Infinity ? -1 : (a - b) / (a + b);
}

Math.tanh() の使用

Math.tanh(0);        // 0
Math.tanh(Infinity); // 1
Math.tanh(1);        // 0.7615941559557649

仕様書

仕様書
{{SpecName('ESDraft', '#sec-math.tanh', 'Math.tanh')}}

ブラウザーの互換性

{{Compat("javascript.builtins.Math.tanh")}}

関連情報