Math.LN2
La propriété Math.LN2 représente le logarithme naturel de 2, environ 0.693:
Exemple interactif
Attributs de Math.LN2 |
|
|---|---|
| Écrivable | Non |
| Énumérable | Non |
| Configurable | Non |
Description
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).
Exemples
Utiliser Math.LN2
La fonction suivante renvoie le logarithme en base 2 d'un nombre en utilisant la valeur de Math.LN2 :
js
function getLog2(x) {
return Math.log(x) / Math.LN2;
}
getLog2(256); // 8
Spécifications
| Specification |
|---|
| ECMAScript Language Specification # sec-math.ln2 |
Compatibilité des navigateurs
BCD tables only load in the browser