Math.log1p()

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.

La fonction Math.log1p() renvoie le logarithme népérien (en base e) d'un nombre +1, donné par la formule :

x>-1,Math.log1p(x)=ln(1+x)\forall x > -1, \mathtt{\operatorname{Math.log1p}(x)} = \ln(1 + x)

Exemple interactif

console.log(Math.log1p(1));
// Expected output: 0.6931471805599453

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

console.log(Math.log1p(-1));
// Expected output: -Infinity

console.log(Math.log1p(-2));
// Expected output: NaN

Syntaxe

js
Math.log1p(x);

Paramètres

x

Un nombre.

Valeur de retour

La valeur du logarithme naturel de 1 plus l'argument (log(1 + x)). Si l'argument est inférieur à -1, NaN est renvoyée.

Description

Si x est strictement inférieur à -1, la valeur renvoyée est NaN.

log1p étant une méthode statique de Math, il faut utiliser Math.log1p() et non pas la méthode d'un autre objet qui aurait été créé (Math n'est pas un constructeur).

Exemple

Utiliser Math.log1p()

js
Math.log1p(1); // 0.6931471805599453
Math.log1p(0); // 0
Math.log1p(-1); // -Infinity
Math.log1p(-2); // NaN

Prothèse d'émulation (polyfill)

Si cette fonction n'est pas disponible, elle peut être définie grâce au code suivant :

js
Math.log1p =
  Math.log1p ||
  function (x) {
    return Math.log(1 + x);
  };

Spécifications

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

Compatibilité des navigateurs

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
log1p

Legend

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

Full support
Full support

Voir aussi