diff options
| author | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2021-09-25 23:28:45 +0900 |
|---|---|---|
| committer | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2021-10-08 02:02:05 +0900 |
| commit | 414856a4d390db8b5873c6585f78c05a18305756 (patch) | |
| tree | 51c98912b7d074c0ed87b177c39cb44189994ce6 /files/ja/web/javascript/reference/operators/remainder | |
| parent | 722252a0dd72f67d8b704e9e869ea9b0cbffde65 (diff) | |
| download | translated-content-414856a4d390db8b5873c6585f78c05a18305756.tar.gz translated-content-414856a4d390db8b5873c6585f78c05a18305756.tar.bz2 translated-content-414856a4d390db8b5873c6585f78c05a18305756.zip | |
JavaScript の算術演算子の文書を更新
- 2021/09/10 時点の英語版に同期
Diffstat (limited to 'files/ja/web/javascript/reference/operators/remainder')
| -rw-r--r-- | files/ja/web/javascript/reference/operators/remainder/index.md | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/files/ja/web/javascript/reference/operators/remainder/index.md b/files/ja/web/javascript/reference/operators/remainder/index.md index 0d757f4d3c..9ca1a6046a 100644 --- a/files/ja/web/javascript/reference/operators/remainder/index.md +++ b/files/ja/web/javascript/reference/operators/remainder/index.md @@ -2,81 +2,79 @@ title: 剰余 (%) slug: Web/JavaScript/Reference/Operators/Remainder tags: -- JavaScript -- Language feature -- Operator -- Reference + - JavaScript + - 言語機能 + - 演算子 + - Reference +browser-compat: javascript.operators.remainder translation_of: Web/JavaScript/Reference/Operators/Remainder --- -<div>{{jsSidebar("Operators")}}</div> +{{jsSidebar("Operators")}} -<p>剰余演算子 (<code>%</code>) は、 1 つ目のオペランドが 2 つ目のオペランドで除算されたときに残った剰余を返します。これは常に被除数の符号を取ります。</p> +剰余演算子 (`%`) は、1 つ目のオペランドが 2 つ目のオペランドで除算されたときに残った剰余を返します。これは常に被除数の符号を取ります。 -<div>{{EmbedInteractiveExample("pages/js/expressions-remainder.html")}}</div> +{{EmbedInteractiveExample("pages/js/expressions-remainder.html")}} -<p>なお、多くの言語では ‘%’ はリマインダー演算子ですが、言語によっては (例えば <a href="https://en.wikipedia.org/wiki/Modulo_operation#In_programming_languages">Python や Perl</a> では) モジュロ演算子になります。正の数同士の場合は、この 2 つの値は等価ですが、被除数と除数が異なる符号の場合は結果が異なります。 JavaScript でモジュロを得るには、 <code>a % n</code> の代わりに <code>((a % n ) + n ) % n</code> を使用してください。</p> +なお、多くの言語では ‘%’ はリマインダー演算子ですが、言語によっては (例えば [Python や Perl](https://en.wikipedia.org/wiki/Modulo_operation#In_programming_languages) では) モジュロ演算子になります。正の数同士の場合は、この 2 つの値は等価ですが、被除数と除数が異なる符号の場合は結果が異なります。 JavaScript でモジュロを得るには、 `a % n` の代わりに `((a % n ) + n ) % n` を使用してください。 -<h2 id="Syntax">構文</h2> +## 構文 -<pre class="brush: js notranslate"><strong>演算子:</strong> <var>var1</var> % <var>var2</var> -</pre> +```js +x % y +``` -<h2 id="Examples">例</h2> +## 例 -<h3 id="Remainder_with_positive_dividend">正の値の剰余</h3> +### 正の値の剰余 -<pre class="brush: js notranslate"> 12 % 5 // 2 +```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">負の値の剰余</h3> +### 負の値の剰余 -<pre class="brush: js notranslate">-12 % 5 // -2 +```js +-12 % 5 // -2 -1 % 2 // -1 --4 % 2 // -0</pre> +-4 % 2 // -0 +``` -<h3 id="Remainder_with_NaN">NaN の剰余</h3> +### NaN の剰余 -<pre class="brush: js notranslate">NaN % 2 // NaN</pre> +```js +NaN % 2 // NaN +``` -<h3 id="Remainder_with_Infinity">無限大の剰余</h3> +### 無限大の剰余 -<pre class="brush: js notranslate">Infinity % 2 // NaN +```js +Infinity % 2 // NaN Infinity % 0 // NaN Infinity % Infinity // NaN -</pre> - -<h2 id="Specifications">仕様書</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">仕様書</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-multiplicative-operators', 'Remainder operator')}} - </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">ブラウザーの互換性</h2> - -<p>{{Compat("javascript.operators.remainder")}}</p> - -<h2 id="See_also">関連項目</h2> - -<ul> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Addition">加算演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Subtraction">減算演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Division">除算演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Multiplication">乗算演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Exponentiation">べき乗演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Increment">インクリメント演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Decrement">デクリメント演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Unary_negation">単項マイナス演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Unary_plus">単項プラス演算子</a></li> -</ul> +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [加算演算子](/ja/docs/Web/JavaScript/Reference/Operators/Addition) +- [減算演算子](/ja/docs/Web/JavaScript/Reference/Operators/Subtraction) +- [除算演算子](/ja/docs/Web/JavaScript/Reference/Operators/Division) +- [乗算演算子](/ja/docs/Web/JavaScript/Reference/Operators/Multiplication) +- [べき乗演算子](/ja/docs/Web/JavaScript/Reference/Operators/Exponentiation) +- [インクリメント演算子](/ja/docs/Web/JavaScript/Reference/Operators/Increment) +- [デクリメント演算子](/ja/docs/Web/JavaScript/Reference/Operators/Decrement) +- [単項マイナス演算子](/ja/docs/Web/JavaScript/Reference/Operators/Unary_negation) +- [単項プラス演算子](/ja/docs/Web/JavaScript/Reference/Operators/Unary_plus) +- [Remainder operator vs. modulo operator](https://2ality.com/2019/08/remainder-vs-modulo.html) +- [Mod and Remainder are not the Same](https://rob.conery.io/2018/08/21/mod-and-remainder-are-not-the-same/) |
