A RetroSearch Logo

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

Search Query:

Showing content from http://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Math/log2 below:

Math.log2() - JavaScript | MDN

Math.log2()

Baseline Widely available

A função Math.log2() retorna o logaritmo de base 2 de um número, que é

∀ 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 Sintaxe Parâmetros

x Um número.

Retorno

O logaritmo de base 2 de um número. Caso o número seja negativo, NaN é retornado.

Descrição

Caso o valor de x seja menor que 0, então o retorno será sempre NaN.

Por log2() ser um método estático de Math, você sempre o usará como Math.log2(), ao invés de usá-lo como método de um objeto Math criado (Math não é um construtor).

Esta função é equivalente a Math.log(x)/Math.log(2). Para log2(e) use a constante Math.LOG2E que é 1 / Math.LN2.

Exemplos 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

Este Polyfill simula a função Math.log2. Note que é retornado um valor não prcesiso Observe que é retornado valores imprecisos em algumas entradas (like 1 << 29), envolva em Math.round() se estiver trabalhando com máscaras de bits.

Math.log2 =
  Math.log2 ||
  function (x) {
    return Math.log(x) * Math.LOG2E;
  };
Especificações Compatibilidade com navegadores Veja também

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