Math.expm1()

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.expm1() gibt e hoch einer Zahl zurück, minus 1. Das bedeutet:

𝙼𝚊𝚝𝚑.𝚎𝚡𝚙𝚖𝟷(𝚡)=ex1\mathtt{\operatorname{Math.expm1}(x)}} = \mathrm{e}^x - 1

Probieren Sie es aus

console.log(Math.expm1(0));
// Expected output: 0

console.log(Math.expm1(1));
// Expected output: 1.718281828459045

console.log(Math.expm1(-1));
// Expected output: -0.6321205588285577

console.log(Math.expm1(2));
// Expected output: 6.38905609893065

Syntax

js
Math.expm1(x)

Parameter

x

Eine Zahl.

Rückgabewert

Eine Zahl, die ex - 1 darstellt, wobei e die Basis des natürlichen Logarithmus ist.

Beschreibung

Für sehr kleine Werte von x kann das Hinzufügen von 1 die Präzision verringern oder eliminieren. Die in JavaScript verwendeten Double-Floats bieten etwa 15 Stellen Präzision. 1 + 1e-15 = 1.000000000000001, aber 1 + 1e-16 = 1.000000000000000 und somit exakt 1.0 in dieser Arithmetik, da Stellen nach der 15. Stelle gerundet werden.

Wenn Sie ex\mathrm{e}^x berechnen, wobei x eine Zahl nahe 0 ist, sollten Sie ein Ergebnis erhalten, das sehr nahe bei 1 + x liegt, da: limx0ex1x=1\lim_{x \to 0} \frac{\mathrm{e}^x - 1}{x} = 1. Wenn Sie Math.exp(1.1111111111e-15) - 1 berechnen, sollten Sie eine Antwort nahe 1.1111111111e-15 erhalten. Stattdessen führt die höchste signifikante Zahl im Ergebnis von Math.exp, nämlich die Ziffer 1, dazu, dass der Endwert 1.1102230246251565e-15 beträgt, mit nur 3 korrekten Stellen. Wenn Sie stattdessen Math.exp1m(1.1111111111e-15) berechnen, erhalten Sie eine deutlich genauere Antwort, 1.1111111111000007e-15, mit 11 korrekten Stellen Präzision.

Da expm1() eine statische Methode von Math ist, verwenden Sie sie immer als Math.expm1() und nicht als Methode eines von Ihnen erstellten Math-Objekts (Math ist kein Konstruktor).

Beispiele

Verwendung von Math.expm1()

js
Math.expm1(-Infinity); // -1
Math.expm1(-1); // -0.6321205588285577
Math.expm1(-0); // -0
Math.expm1(0); // 0
Math.expm1(1); // 1.718281828459045
Math.expm1(Infinity); // Infinity

Spezifikationen

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

Browser-Kompatibilität

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
expm1

Legend

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

Full support
Full support

Siehe auch