Skip to content

Commit 651bbc7

Browse files
committed
fix: 0除算の結果がエラーにならず、Infinityになることの説明追記(#1616)
1 parent 7e453c1 commit 651bbc7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

source/basic/operator/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,20 @@ console.log(10 * 0.5); // => 5
111111
```js
112112
console.log(8 / 2); // => 4
113113
console.log(10 / 0.5); // => 20
114+
115+
// 正の無限大
116+
console.log(10 / 0); // => Infinity
117+
console.log(-10 / -0); // => Infinity
118+
// 負の無限大
119+
console.log(-10 / 0); // => -Infinity
120+
console.log(10 / -0); // => -Infinity
114121
```
115122

123+
0で除算した場合、無限大を表す数値である`Infinity`として評価されます。
124+
演算結果が0未満で表される場合は、負の無限大を表す`-Infinity`となります。
125+
126+
四則演算において、式の一部でInfinityと評価されてしまうと、式全体の演算結果も意図しないものとなります。そのため、除算演算子を使う場合には右オペランドの値が0になるケースには注意が必要です。
127+
116128
### 剰余演算子(`%`) {#modulus-operator}
117129

118130
2つの数値を除算したあまりを求める演算子です。左オペランドを右オペランドで除算したあまりを返します。

0 commit comments

Comments
 (0)