Baseline Widely available
La fonction Math.log2()
renvoie le logarithme en base 2 d'un nombre :
â x > 0 , Math.log2 ( x ) = log 2 ( x ) = l'unique y tel que 2y = x \forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} ; y ; \text{such that} ; 2^y = x
Exemple interactifconsole.log(Math.log2(3));
// Expected output: 1.584962500721156
console.log(Math.log2(2));
// Expected output: 1
console.log(Math.log2(1));
// Expected output: 0
console.log(Math.log2(0));
// Expected output: -Infinity
Syntaxe Paramètres Valeur de retour
Le logarithme en base 2 du nombre passé en argument. Si ce nombre est négatif, c'est NaN
qui sera renvoyé.
Si x
est strictement inférieur à 0, la valeur renvoyée sera NaN
.
log2()
étant une méthode statique de Math
, il faut utiliser Math.log2()
et non pas la méthode d'un autre objet qui aurait été créé (Math
n'est pas un constructeur). Si on souhaite utiliser des constantes, on pourra employer Math.LOG2E
ou Math.LN2
.
Math.log2()
Math.log2(3); // 1.584962500721156
Math.log2(2); // 1
Math.log2(1); // 0
Math.log2(0); // -Infinity
Math.log2(-2); // NaN
Math.log2(1024); // 10
Spécifications Compatibilité des navigateurs Voir aussi
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4