aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/operators/remainder/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/fr/web/javascript/reference/operators/remainder/index.html')
-rw-r--r--files/fr/web/javascript/reference/operators/remainder/index.html80
1 files changed, 80 insertions, 0 deletions
diff --git a/files/fr/web/javascript/reference/operators/remainder/index.html b/files/fr/web/javascript/reference/operators/remainder/index.html
new file mode 100644
index 0000000000..c5df6dd43d
--- /dev/null
+++ b/files/fr/web/javascript/reference/operators/remainder/index.html
@@ -0,0 +1,80 @@
+---
+title: Reste (%)
+slug: Web/JavaScript/Reference/Operators/Remainder
+tags:
+ - JavaScript
+ - Language feature
+ - Operator
+ - Reference
+browser-compat: javascript.operators.remainder
+translation-of: Web/JavaScript/Reference/Operators/Remainder
+---
+<div>{{jsSidebar("Operators")}}</div>
+
+<p>L'opérateur du reste (<code>%</code>) renvoie le reste de la division de l'opérande gauche par l'opérande droit. Le résultat a toujours le signe du numérateur.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/expressions-remainder.html")}}</div>
+
+<p>Bien que dans la plupart des langages, <code>%</code> est un opérateur de reste, pour d'autres (par exemple <a href="https://en.wikipedia.org/wiki/Modulo_operation#In_programming_languages">Python, Perl</a>) c'est un opérateur de modulo. Lorsqu'on utilise des valeurs positives, les deux opérateurs sont équivalents mais lorsque le numérateur et de dénominateur ont des signes différents, le reste et le modulo fourniront des signes différents. Pour obtenir une opération équivalente au modulo en JavaScript, on pourra utiliser <code>((a % n ) + n ) % n</code>.</p>
+
+<h2 id="syntax">Syntaxe</h2>
+
+<pre class="brush: js">
+<strong>Opérateur :</strong> <var>var1</var> % <var>var2</var>
+</pre>
+
+<h2 id="examples">Exemples</h2>
+
+<h3 id="remainder_with_positive_dividend">Reste avec numérateur positif</h3>
+
+<pre class="brush: js">
+12 % 5 // 2
+ 1 % -2 // 1
+ 1 % 2 // 1
+ 2 % 3 // 2
+5.5 % 2 // 1.5
+</pre>
+
+<h3 id="remainder_with_negative_dividend">Reste avec numérateur négatif</h3>
+
+<pre class="brush: js">
+-12 % 5 // -2
+-1 % 2 // -1
+-4 % 2 // -0
+</pre>
+
+<h3 id="remainder_with_nan">Reste avec NaN</h3>
+
+<pre class="brush: js">
+NaN % 2 // NaN
+</pre>
+
+<h3 id="remainder_with_infinity">Reste avec l'infini</h3>
+
+<pre class="brush: js">
+Infinity % 2 // NaN
+Infinity % 0 // NaN
+Infinity % Infinity // NaN
+</pre>
+
+<h2 id="specifications">Spécifications</h2>
+
+<p>{{Specifications}}</p>
+
+<h2 id="browser_compatibility">Compatibilité des navigateurs</h2>
+
+<p>{{Compat}}</p>
+
+<h2 id="see_also">Voir aussi</h2>
+
+<ul>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Addition">Opérateur d'addition</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Subtraction">Opérateur de soustraction</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Multiplication">Opérateur de multiplication</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Division">Opérateur de division</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Exponentiation">Opérateur d'exponentiation</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Increment">Opérateur d'incrémentation</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Decrement">Opérateur de décrémentation</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Unary_negation">Opérateur de négation unaire</a></li>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Unary_plus">Opérateur plus unaire</a></li>
+</ul>