Math.tanh()
Math.tanh()
関数は、引数として与えた数のハイパーボリックタンジェントを返します。すなわち
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
構文
Math.tanh(x)
引数
x
- 数値。
返値
指定された数値のハイパーボリックタンジェントです。
解説
tanh()
は Math
の静的メソッドであるため、生成した Math
オブジェクトのメソッドとしてではなく、常に Math.tanh()
として使用するようにしてください (Math
はコンストラクターではありません)。
ポリフィル
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
仕様書
ブラウザーの互換性
BCD tables only load in the browser