From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../reference/global_objects/math/log2/index.html | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/math/log2/index.html (limited to 'files/es/web/javascript/reference/global_objects/math/log2') diff --git a/files/es/web/javascript/reference/global_objects/math/log2/index.html b/files/es/web/javascript/reference/global_objects/math/log2/index.html new file mode 100644 index 0000000000..b394270684 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/math/log2/index.html @@ -0,0 +1,96 @@ +--- +title: Math.log2() +slug: Web/JavaScript/Referencia/Objetos_globales/Math/log2 +translation_of: Web/JavaScript/Reference/Global_Objects/Math/log2 +--- +
{{JSRef}}
+ +

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

+ +

x>0,Math.log2(x)=log2(x)=the uniqueysuch that2y=x\forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} \; y \; \text{such that} \; 2^y = x

+ +
{{EmbedInteractiveExample("pages/js/math-log2.html")}}
+ + + +

Syntax

+ +
Math.log2(x)
+ +

Parámetros

+ +
+
x
+
Un número.
+
+ +

Valor de retorno

+ +

El logaritmo base 2 del número usado como parámetro. Si el número es negativo, {{jsxref("NaN")}} será retornado.

+ +

Descripción

+ +

Si el valor de x es mejor a 0, el valor de retorno es siempre {{jsxref("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 {{jsxref("Math.LOG2E")}} que es 1 / {{jsxref("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 {{jsxref("Math.round()")}} if working with bit masks.

+ +
Math.log2 = Math.log2 || function(x) {
+  return Math.log(x) * Math.LOG2E;
+};
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES2015', '#sec-math.log2', 'Math.log2')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-math.log2', 'Math.log2')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibility

+ + + +

{{Compat("javascript.builtins.Math.log2")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf