--- title: Math.LN2 slug: Web/JavaScript/Reference/Global_Objects/Math/LN2 tags: - JavaScript - Math - Property - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Math/LN2 ---
Die Math.LN2 Eigenschaft repräsentiert den natürlichen Logarithmus von 2, was gerundet 0,693 ist:
Weil LN2 eine statische Eigenschaft von Math ist, kann diese immer mit Math.LN2 erreicht werden, ohne dass ein Objekt von Math erstellt werden muss (Math ist kein Konstruktor).
Math.LN2Die folgende Funktion gibt den Logarithmus zur Basis 2 von einer Zahl zurück. Dabei wird Math.LN2 benutzt:
function getLog2(x) {
return Math.log(x) / Math.LN2;
}
getLog2(256) // 8
| Spezifikation | Status | Kommentar |
|---|---|---|
| {{SpecName('ES1')}} | {{Spec2('ES1')}} | Initiale Definition. Implementiert in 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")}}