aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/math/log2
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/web/javascript/reference/global_objects/math/log2')
-rw-r--r--files/es/web/javascript/reference/global_objects/math/log2/index.html97
1 files changed, 97 insertions, 0 deletions
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..8d8d45c60c
--- /dev/null
+++ b/files/es/web/javascript/reference/global_objects/math/log2/index.html
@@ -0,0 +1,97 @@
+---
+title: Math.log2()
+slug: Web/JavaScript/Reference/Global_Objects/Math/log2
+translation_of: Web/JavaScript/Reference/Global_Objects/Math/log2
+original_slug: Web/JavaScript/Referencia/Objetos_globales/Math/log2
+---
+<div>{{JSRef}}</div>
+
+<p>La función <strong><code>Math.log2()</code></strong> retorna el logaritmo base 2 de un número, esto es</p>
+
+<p><math display="block"><semantics><mrow><mo>∀</mo><mi>x</mi><mo>&gt;</mo><mn>0</mn><mo>,</mo><mstyle mathvariant="monospace"><mrow><mo lspace="0em" rspace="thinmathspace">Math.log2</mo><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mstyle><mo>=</mo><msub><mo lspace="0em" rspace="0em">log</mo><mn>2</mn></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mtext>the unique</mtext><mspace width="thickmathspace"></mspace><mi>y</mi><mspace width="thickmathspace"></mspace><mtext>such that</mtext><mspace width="thickmathspace"></mspace><msup><mn>2</mn><mi>y</mi></msup><mo>=</mo><mi>x</mi></mrow><annotation encoding="TeX">\forall x &gt; 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} \; y \; \text{such that} \; 2^y = x</annotation></semantics></math></p>
+
+<div>{{EmbedInteractiveExample("pages/js/math-log2.html")}}</div>
+
+
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><code>Math.log2(<var>x</var>)</code></pre>
+
+<h3 id="Parámetros">Parámetros</h3>
+
+<dl>
+ <dt><code>x</code></dt>
+ <dd>Un número.</dd>
+</dl>
+
+<h3 id="Valor_de_retorno">Valor de retorno</h3>
+
+<p>El logaritmo base 2 del número usado como parámetro. Si el número es negativo, {{jsxref("NaN")}} será retornado.</p>
+
+<h2 id="Descripción">Descripción</h2>
+
+<p>Si el valor de <code>x</code> es mejor a 0, el valor de retorno es siempre {{jsxref("NaN")}}.</p>
+
+<p>Debido a que <code>log2()</code> es una función estática de <code>Math</code>, siempre debe ser usado como <code>Math.log2()</code>, en lugar de ser usado como un método del objeto <code>Math</code> (<code>Math</code> no es un constructor).</p>
+
+<p>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")}}.  </p>
+
+<h2 id="Ejemplos">Ejemplos</h2>
+
+<h3 id="Usando_Math.log2()">Usando <code>Math.log2()</code></h3>
+
+<pre class="brush: js">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
+</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<p>This Polyfill emulates the <code>Math.log2</code> function. Note that it returns imprecise values on some inputs (like 1 &lt;&lt; 29), wrap into {{jsxref("Math.round()")}} if working with bit masks.</p>
+
+<pre class="brush: js">Math.log2 = Math.log2 || function(x) {
+ return Math.log(x) * Math.LOG2E;
+};
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-math.log2', 'Math.log2')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-math.log2', 'Math.log2')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.Math.log2")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("Math.exp()")}}</li>
+ <li>{{jsxref("Math.log()")}}</li>
+ <li>{{jsxref("Math.log10()")}}</li>
+ <li>{{jsxref("Math.log1p()")}}</li>
+ <li>{{jsxref("Math.pow()")}}</li>
+</ul>