diff options
Diffstat (limited to 'files/fr/web/javascript/reference/global_objects/math/log2')
| -rw-r--r-- | files/fr/web/javascript/reference/global_objects/math/log2/index.md | 94 |
1 files changed, 38 insertions, 56 deletions
diff --git a/files/fr/web/javascript/reference/global_objects/math/log2/index.md b/files/fr/web/javascript/reference/global_objects/math/log2/index.md index c1700ae5c1..8d9d91c64b 100644 --- a/files/fr/web/javascript/reference/global_objects/math/log2/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/log2/index.md @@ -11,79 +11,61 @@ tags: translation_of: Web/JavaScript/Reference/Global_Objects/Math/log2 original_slug: Web/JavaScript/Reference/Objets_globaux/Math/log2 --- -<div>{{JSRef}}</div> +{{JSRef}} -<p>La fonction <code><strong>Math.log2()</strong></code> renvoie le logarithme en base 2 d'un nombre :</p> +La fonction **`Math.log2()`** renvoie le logarithme en base 2 d'un nombre : -<p><math><semantics><mrow><mo>∀</mo><mi>x</mi><mo>></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>l'unique </mtext><mspace width="thickmathspace"></mspace><mi>y</mi><mspace width="thickmathspace"></mspace><mtext>tel que</mtext><mspace width="thickmathspace"></mspace><msup><mn>2</mn><mi>y</mi></msup><mo>=</mo><mi>x</mi></mrow><annotation encoding="TeX">\forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} \; y \; \text{such that} \; 2^y = x</annotation></semantics></math></p> +<math><semantics><mrow><mo>∀</mo><mi>x</mi><mo>></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>l'unique </mtext><mspace width="thickmathspace"></mspace><mi>y</mi><mspace width="thickmathspace"></mspace><mtext>tel que</mtext><mspace width="thickmathspace"></mspace><msup><mn>2</mn><mi>y</mi></msup><mo>=</mo><mi>x</mi></mrow><annotation encoding="TeX">\forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} \; y \; \text{such that} \; 2^y = x</annotation></semantics></math> -<div>{{EmbedInteractiveExample("pages/js/math-log2.html")}}</div> +{{EmbedInteractiveExample("pages/js/math-log2.html")}} -<h2 id="Syntaxe">Syntaxe</h2> +## Syntaxe -<pre class="syntaxbox">Math.log2(<var>x</var>)</pre> + Math.log2(x) -<h3 id="Paramètres">Paramètres</h3> +### Paramètres -<dl> - <dt><code>x</code></dt> - <dd>Un nombre.</dd> -</dl> +- `x` + - : Un nombre. -<h3 id="Valeur_de_retour">Valeur de retour</h3> +### Valeur de retour -<p>Le logarithme en base 2 du nombre passé en argument. Si ce nombre est négatif, c'est {{jsxref("NaN")}} qui sera renvoyé.</p> +Le logarithme en base 2 du nombre passé en argument. Si ce nombre est négatif, c'est {{jsxref("NaN")}} qui sera renvoyé. -<h2 id="Description">Description</h2> +## Description -<p>Si <code>x</code> est strictement inférieur à 0, la valeur renvoyée sera {{jsxref("NaN")}}.</p> +Si `x` est strictement inférieur à 0, la valeur renvoyée sera {{jsxref("NaN")}}. -<p><code>log2()</code> étant une méthode statique de <code>Math</code>, il faut utiliser <code>Math.<code>log2</code>()</code> et non pas la méthode d'un autre objet qui aurait été créé (<code>Math </code>n'est pas un constructeur). Si on souhaite utiliser des constantes, on pourra employer {{jsxref("Math.LOG2E")}} ou {{jsxref("Math.LN2")}}.</p> +`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 {{jsxref("Math.LOG2E")}} ou {{jsxref("Math.LN2")}}. -<h2 id="Exemples">Exemples</h2> +## Exemples -<h3 id="Utiliser_Math.log2()">Utiliser <code>Math.log2()</code></h3> +### Utiliser `Math.log2()` -<pre class="brush:js">Math.log2(3); // 1.584962500721156 +```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="Spécifications">Spécifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Spécification</th> - <th scope="col">État</th> - <th scope="col">Commentaires</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-math.log2', 'Math.log2')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Définition initiale.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-math.log2', 'Math.log2')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> - -<p>{{Compat("javascript.builtins.Math.log2")}}</p> - -<h2 id="Voir_aussi">Voir aussi</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> +``` + +## Spécifications + +| Spécification | État | Commentaires | +| ------------------------------------------------------------------------ | ---------------------------- | -------------------- | +| {{SpecName('ES2015', '#sec-math.log2', 'Math.log2')}} | {{Spec2('ES2015')}} | Définition initiale. | +| {{SpecName('ESDraft', '#sec-math.log2', 'Math.log2')}} | {{Spec2('ESDraft')}} | | + +## Compatibilité des navigateurs + +{{Compat("javascript.builtins.Math.log2")}} + +## Voir aussi + +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log10()")}} +- {{jsxref("Math.log1p()")}} +- {{jsxref("Math.pow()")}} |
