aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/global_objects/math/hypot
diff options
context:
space:
mode:
authorjulieng <julien.gattelier@gmail.com>2021-08-03 08:03:23 +0200
committerSphinxKnight <SphinxKnight@users.noreply.github.com>2021-09-03 08:08:25 +0200
commitbf8e099b9c8b3c60d60b3712b4fc97b052c39887 (patch)
treec101746d082c9581c94f5937519c7d0e2f4af8cb /files/fr/web/javascript/reference/global_objects/math/hypot
parent844f5103992238c0c23203286dad16a466e89c97 (diff)
downloadtranslated-content-bf8e099b9c8b3c60d60b3712b4fc97b052c39887.tar.gz
translated-content-bf8e099b9c8b3c60d60b3712b4fc97b052c39887.tar.bz2
translated-content-bf8e099b9c8b3c60d60b3712b4fc97b052c39887.zip
convert content to md
Diffstat (limited to 'files/fr/web/javascript/reference/global_objects/math/hypot')
-rw-r--r--files/fr/web/javascript/reference/global_objects/math/hypot/index.md120
1 files changed, 52 insertions, 68 deletions
diff --git a/files/fr/web/javascript/reference/global_objects/math/hypot/index.md b/files/fr/web/javascript/reference/global_objects/math/hypot/index.md
index bba9aaebe8..977f6c4965 100644
--- a/files/fr/web/javascript/reference/global_objects/math/hypot/index.md
+++ b/files/fr/web/javascript/reference/global_objects/math/hypot/index.md
@@ -11,59 +11,59 @@ tags:
translation_of: Web/JavaScript/Reference/Global_Objects/Math/hypot
original_slug: Web/JavaScript/Reference/Objets_globaux/Math/hypot
---
-<div>{{JSRef}}</div>
+{{JSRef}}
-<p>La fonction <code><strong>Math.hypot()</strong></code> renvoie la racine carrée de la somme des carrés de ses arguments. On peut également la définir avec la formule suivante :</p>
+La fonction **`Math.hypot()`** renvoie la racine carrée de la somme des carrés de ses arguments. On peut également la définir avec la formule suivante :
-<p><math display="block"><semantics><mrow><mstyle mathvariant="monospace"><mrow><mo lspace="0em" rspace="thinmathspace">Math.hypot</mo><mo stretchy="false">(</mo><msub><mi>v</mi><mn>1</mn></msub><mo>,</mo><msub><mi>v</mi><mn>2</mn></msub><mo>,</mo><mo>…</mo><mo>,</mo><msub><mi>v</mi><mi>n</mi></msub><mo stretchy="false">)</mo></mrow></mstyle><mo>=</mo><msqrt><mrow><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><msubsup><mi>v</mi><mi>i</mi><mn>2</mn></msubsup></mrow></msqrt><mo>=</mo><msqrt><mrow><msubsup><mi>v</mi><mn>1</mn><mn>2</mn></msubsup><mo>+</mo><msubsup><mi>v</mi><mn>2</mn><mn>2</mn></msubsup><mo>+</mo><mo>…</mo><mo>+</mo><msubsup><mi>v</mi><mi>n</mi><mn>2</mn></msubsup></mrow></msqrt></mrow><annotation encoding="TeX">\mathtt{\operatorname{Math.hypot}(v_1, v_2, \dots, v_n)} = \sqrt{\sum_{i=1}^n v_i^2} = \sqrt{v_1^2 + v_2^2 + \dots + v_n^2}</annotation></semantics></math></p>
+<math display="block"><semantics><mrow><mstyle mathvariant="monospace"><mrow><mo lspace="0em" rspace="thinmathspace">Math.hypot</mo><mo stretchy="false">(</mo><msub><mi>v</mi><mn>1</mn></msub><mo>,</mo><msub><mi>v</mi><mn>2</mn></msub><mo>,</mo><mo>…</mo><mo>,</mo><msub><mi>v</mi><mi>n</mi></msub><mo stretchy="false">)</mo></mrow></mstyle><mo>=</mo><msqrt><mrow><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><msubsup><mi>v</mi><mi>i</mi><mn>2</mn></msubsup></mrow></msqrt><mo>=</mo><msqrt><mrow><msubsup><mi>v</mi><mn>1</mn><mn>2</mn></msubsup><mo>+</mo><msubsup><mi>v</mi><mn>2</mn><mn>2</mn></msubsup><mo>+</mo><mo>…</mo><mo>+</mo><msubsup><mi>v</mi><mi>n</mi><mn>2</mn></msubsup></mrow></msqrt></mrow><annotation encoding="TeX">\mathtt{\operatorname{Math.hypot}(v*1, v_2, \dots, v_n)} = \sqrt{\sum*{i=1}^n v_i^2} = \sqrt{v_1^2 + v_2^2 + \dots + v_n^2}</annotation></semantics></math>
-<div>{{EmbedInteractiveExample("pages/js/math-hypot.html")}}</div>
+{{EmbedInteractiveExample("pages/js/math-hypot.html")}}
-<h2 id="Syntaxe">Syntaxe</h2>
+## Syntaxe
-<pre class="syntaxbox">Math.hypot([valeur<var>1</var>[,<var>valeur2</var>, ...]]) </pre>
+ Math.hypot([valeur1[,valeur2, ...]])
-<h3 id="Paramètres">Paramètres</h3>
+### Paramètres
-<dl>
- <dt><code>valeur1, valeur2, ...</code></dt>
- <dd>Des nombres.</dd>
-</dl>
+- `valeur1, valeur2, ...`
+ - : Des nombres.
-<h3 id="Valeur_de_retour">Valeur de retour</h3>
+### Valeur de retour
-<p>La racine carrée de la somme des carrés des arguments. S'il existe un des arguments qui ne peut pas être converti en un nombre, c'est la valeur {{jsxref("NaN")}} qui sera renvoyée.</p>
+La racine carrée de la somme des carrés des arguments. S'il existe un des arguments qui ne peut pas être converti en un nombre, c'est la valeur {{jsxref("NaN")}} qui sera renvoyée.
-<h2 id="Description">Description</h2>
+## Description
-<p><code>hypot()</code> étant une méthode statique de <code>Math</code>, il faut utiliser <code>Math.<code>hypot</code>()</code>et non pas la méthode d'un autre objet qui aurait été créé (<code>Math</code> n'est pas un constructeur).</p>
+`hypot()` étant une méthode statique de `Math`, il faut utiliser `Math.hypot()`et non pas la méthode d'un autre objet qui aurait été créé (`Math` n'est pas un constructeur).
-<p>Si aucun argument n'est donné, le résultat sera +0.Si, parmi les arguments, au moins un ne peut pas être converti en un nombre, le résultat sera {{jsxref("NaN")}}.Si cette fonction est utilisée avec un argument : <code>Math.hypot(x)</code> sera équivalente à <code>Math.abs(x)</code>.</p>
+Si aucun argument n'est donné, le résultat sera +0.Si, parmi les arguments, au moins un ne peut pas être converti en un nombre, le résultat sera {{jsxref("NaN")}}.Si cette fonction est utilisée avec un argument : `Math.hypot(x)` sera équivalente à `Math.abs(x)`.
-<p>Cette fonction permet entre autres de gérer certains cas où, pour les grands nombres, l'utilisation de {{jsxref("Math.sqrt()")}} aurait renvoyé {{jsxref("Infinity")}} à cause des calculs intermédiaires.</p>
+Cette fonction permet entre autres de gérer certains cas où, pour les grands nombres, l'utilisation de {{jsxref("Math.sqrt()")}} aurait renvoyé {{jsxref("Infinity")}} à cause des calculs intermédiaires.
-<h2 id="Exemples">Exemples</h2>
+## Exemples
-<h3 id="Utiliser_Math.hypot()">Utiliser <code>Math.hypot()</code></h3>
+### Utiliser `Math.hypot()`
-<pre class="brush:js">Math.hypot(3, 4) // 5
+```js
+Math.hypot(3, 4) // 5
Math.hypot(3, 4, 5) // 7.0710678118654755
Math.hypot() // 0
Math.hypot(NaN) // NaN
-Math.hypot(3, 4, "toto") // NaN, +"toto" =&gt; NaN
-Math.hypot(3, 4, "5") // 7.0710678118654755, +"5" =&gt; 5
+Math.hypot(3, 4, "toto") // NaN, +"toto" => NaN
+Math.hypot(3, 4, "5") // 7.0710678118654755, +"5" => 5
Math.hypot(-3) // 3, the same as Math.abs(-3)
-</pre>
+```
-<h2 id="Prothèse_d'émulation_(polyfill)">Prothèse d'émulation (<em>polyfill</em>)</h2>
+## Prothèse d'émulation (_polyfill_)
-<p>Si elle n'est pas disponible, cette fonction peut être émulée de la façon suivante :</p>
+Si elle n'est pas disponible, cette fonction peut être émulée de la façon suivante :
-<pre class="brush: js">Math.hypot = Math.hypot || function() {
+```js
+Math.hypot = Math.hypot || function() {
var y = 0;
var length = arguments.length;
- for (var i = 0; i &lt; length; i++) {
+ for (var i = 0; i < length; i++) {
if(arguments[i] === Infinity || arguments[i] === -Infinity) {
return Infinity;
}
@@ -71,56 +71,40 @@ Math.hypot(-3) // 3, the same as Math.abs(-3)
}
return Math.sqrt(y);
};
-</pre>
+```
-<p>Voici une seconde version qui évite les dépassements :</p>
+Voici une seconde version qui évite les dépassements :
-<pre class="brush: js">Math.hypot = function (x, y) {
+```js
+Math.hypot = function (x, y) {
// https://bugzilla.mozilla.org/show_bug.cgi?id=896264#c28
var max = 0;
var s = 0;
- for (var i = 0; i &lt; arguments.length; i += 1) {
+ for (var i = 0; i < arguments.length; i += 1) {
var arg = Math.abs(Number(arguments[i]));
- if (arg &gt; max) {
+ if (arg > max) {
s *= (max / arg) * (max / arg);
max = arg;
}
- s += arg === 0 &amp;&amp; max === 0 ? 0 : (arg / max) * (arg / max);
+ s += arg === 0 && max === 0 ? 0 : (arg / max) * (arg / max);
}
return max === 1 / 0 ? 1 / 0 : max * Math.sqrt(s);
};
-</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.hypot', 'Math.hypot')}}</td>
- <td>{{Spec2('ES2015')}}</td>
- <td>Définition initiale</td>
- </tr>
- <tr>
- <td>{{SpecName('ESDraft', '#sec-math.hypot', 'Math.hypot')}}</td>
- <td>{{Spec2('ESDraft')}}</td>
- <td> </td>
- </tr>
- </tbody>
-</table>
-
-<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
-
-<p>{{Compat("javascript.builtins.Math.hypot")}}</p>
-
-<h2 id="Voir_aussi">Voir aussi</h2>
-
-<ul>
- <li>{{jsxref("Math.abs()")}}</li>
- <li>{{jsxref("Math.pow()")}}</li>
- <li>{{jsxref("Math.sqrt()")}}</li>
-</ul>
+```
+
+## Spécifications
+
+| Spécification | État | Commentaires |
+| ---------------------------------------------------------------------------- | ---------------------------- | ------------------- |
+| {{SpecName('ES2015', '#sec-math.hypot', 'Math.hypot')}} | {{Spec2('ES2015')}} | Définition initiale |
+| {{SpecName('ESDraft', '#sec-math.hypot', 'Math.hypot')}} | {{Spec2('ESDraft')}} |   |
+
+## Compatibilité des navigateurs
+
+{{Compat("javascript.builtins.Math.hypot")}}
+
+## Voir aussi
+
+- {{jsxref("Math.abs()")}}
+- {{jsxref("Math.pow()")}}
+- {{jsxref("Math.sqrt()")}}