--- title: Math.LN2 slug: Web/JavaScript/Reference/Global_Objects/Math/LN2 tags: - JavaScript - Math - Propriété - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Math/LN2 original_slug: Web/JavaScript/Reference/Objets_globaux/Math/LN2 ---
La propriété Math.LN2 représente le logarithme naturel de 2, environ 0.693:
Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner https://github.com/mdn/interactive-examples et à envoyer une pull request !
LN2 est une propriété statique de l'objet Math, il doit toujours être utilisé avec la syntaxe Math.LN2, et non pas être utilisé comme la propriété d'un objet qui aurait été créé (Math n'est pas un constructeur).
Math.LN2La fonction suivante renvoie le logarithme en base 2 d'un nombre en utilisant la valeur de Math.LN2 :
function getLog2(x) {
return Math.log(x) / Math.LN2;
}
getLog2(256); // 8
| Spécification | Statut | Commentaires |
|---|---|---|
| {{SpecName('ES1')}} | {{Spec2('ES1')}} | Définition initiale. Implémentée avec JavaScript 1.0. |
| {{SpecName('ES5.1', '#sec-15.8.1.3', 'Math.LN2')}} | {{Spec2('ES5.1')}} | |
| {{SpecName('ES6', '#sec-math.ln2', 'Math.LN2')}} | {{Spec2('ES6')}} | |
| {{SpecName('ESDraft', '#sec-math.ln2', 'Math.LN2')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Math.LN2")}}