A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Math/log2 below:

Math.log2() - JavaScript | MDN

Math.log2()

Baseline Widely available

La función Math.log2() retorna el logaritmo base 2 de un número, esto es

∀ x > 0 , Math.log2 ( x ) = log 2 ( x ) = the unique y such that 2y = x \forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} ; y ; \text{such that} ; 2^y = x Pruébalo
console.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
Syntax Parámetros Valor de retorno

El logaritmo base 2 del número usado como parámetro. Si el número es negativo, NaN será retornado.

Descripción

Si el valor de x es mejor a 0, el valor de retorno es siempre NaN.

Debido a que log2() es una función estática de Math, siempre debe ser usado como Math.log2(), en lugar de ser usado como un método del objeto Math (Math no es un constructor).

Esta función es equivalente a Math.log(x) / Math.log(2). Para log2(e) use la constante Math.LOG2E que es 1 / Math.LN2.

Ejemplos Usando 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
Polyfill

This Polyfill emulates the Math.log2 function. Note that it returns imprecise values on some inputs (like 1 << 29), wrap into Math.round() if working with bit masks.

Math.log2 =
  Math.log2 ||
  function (x) {
    return Math.log(x) * Math.LOG2E;
  };
Especificaciones Compatibilidad con navegadores See also

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