Skip to content

Commit

Permalink
feat(Tutorial): 🐛 Tutorials for operators updated && a bug in modulo …
Browse files Browse the repository at this point in the history
…calculating fixed.

Bug fixed: when modulo operator is applied on two int typed Number value, will cause the program panic.
  • Loading branch information
BHznJNs committed Aug 29, 2023
1 parent 844da5b commit 9c357b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/public/value/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl Number {
}

match (dividend, divisor) {
(Self::Int(i1), Self::Int(i2)) => Number::Int(i1 % i2),
(Self::Int(i), Self::Fraction(upper, lower)) | (Self::Fraction(upper, lower), Self::Int(i)) => {
let temp1 = i * lower;
let temp2 = upper * lower;
Expand Down
4 changes: 4 additions & 0 deletions tutorials/CN/语法教程/operators.calcrs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ out 1 + 2 # 3
out 1 - 2 # -1
out 1 * 2 # 2
out 1 / 2 # 0.5000000000

# 模运算
out 8 % 2 # 0
# 乘方运算
out 2 ^ 2 # 4

# 非操作符
Expand Down
4 changes: 4 additions & 0 deletions tutorials/EN/syntax/operators.calcrs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ out 1 + 2 # 3
out 1 - 2 # -1
out 1 * 2 # 2
out 1 / 2 # 0.5000000000

# modular operator
out 8 % 2 # 0
# power operator
out 2 ^ 2 # 4

# not operator
Expand Down

0 comments on commit 9c357b8

Please sign in to comment.