Math.tan()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Math.tan() 静的メソッドは、数値の正接(タンジェント)を返します。

試してみましょう

function getTanFromDegrees(degrees) {
  return Math.tan((degrees * Math.PI) / 180);
}

console.log(getTanFromDegrees(0));
// Expected output: 0

console.log(getTanFromDegrees(45));
// Expected output: 0.9999999999999999

console.log(getTanFromDegrees(90));
// Expected output: 16331239353195370

構文

js
Math.tan(x)

引数

x

ラジアンで角度を表す数値です。

返値

x の正接(タンジェント)です。 xInfinity の場合は -InfinityNaN の場合は NaN を返します。

メモ: 浮動小数点の精度により、正確な値 π/2 を得ることはできないため、 NaN でなければ、結果は常に有限となります。

解説

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

Math.tan() の使用

js
Math.tan(-Infinity); // NaN
Math.tan(-0); // -0
Math.tan(0); // 0
Math.tan(1); // 1.5574077246549023
Math.tan(Math.PI / 4); // 0.9999999999999999 (浮動小数点エラー)
Math.tan(Infinity); // NaN

Math.tan() および π/2

正確に tan(π/2) を計算することはでいません。

js
Math.tan(Math.PI / 2); // 16331239353195370
Math.tan(Math.PI / 2 + Number.EPSILON); // -6218431163823738

Math.tan() に角度の値を使用

Math.tan() 関数はラジアンを受け付けますが、角度で使用したほうが簡単な場合が多いので、次の関数は角度の値を受け付け、それをラジアンに変換してタンジェントを返します。

js
function getTanDeg(deg) {
  const rad = (deg * Math.PI) / 180;
  return Math.tan(rad);
}

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-math.tan

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
tan

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報