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.
Die statische Methode Math.tan()
gibt die Tangente einer Zahl im Bogenmaß zurück.
Probieren Sie es aus
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
Syntax
Math.tan(x)
Parameter
x
-
Eine Zahl, die einen Winkel im Bogenmaß repräsentiert.
Rückgabewert
Beschreibung
Da tan()
eine statische Methode von Math
ist, wird sie immer als Math.tan()
verwendet und nicht als Methode eines von Ihnen erstellten Math
-Objekts (Math
ist kein Konstruktor).
Beispiele
Verwendung von Math.tan()
Math.tan(-Infinity); // NaN
Math.tan(-0); // -0
Math.tan(0); // 0
Math.tan(1); // 1.5574077246549023
Math.tan(Math.PI / 4); // 0.9999999999999999 (Floating point error)
Math.tan(Infinity); // NaN
Math.tan() und π/2
Es ist nicht möglich, tan(π/2)
exakt zu berechnen.
Math.tan(Math.PI / 2); // 16331239353195370
Math.tan(Math.PI / 2 + Number.EPSILON); // -6218431163823738
Verwendung von Math.tan() mit einem Gradwert
Da die Funktion Math.tan()
Bogenmaß erwartet, es jedoch oft einfacher ist, mit Gradwerten zu arbeiten, akzeptiert die folgende Funktion einen Wert in Grad, konvertiert ihn in Bogenmaß und gibt die Tangente zurück.
function getTanDeg(deg) {
const rad = (deg * Math.PI) / 180;
return Math.tan(rad);
}
Spezifikationen
Specification |
---|
ECMAScript® 2025 Language Specification # sec-math.tan |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tan |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support