enforce integer division via explicit builtins
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
# Milestone 6: compound assignment (`+=`, `-=`, `*=`, `/=`) and the binary
|
||||
# arithmetic operators `-`, `*`, `/` with multiplicative precedence.
|
||||
# Compound assignment (`+=`, `-=`, `*=`, `/=`) and explicit integer division.
|
||||
|
||||
check_float func() i32 {
|
||||
x f64 = 10.0
|
||||
@@ -15,7 +14,7 @@ check_float func() i32 {
|
||||
|
||||
check_unsigned func() i32 {
|
||||
n u32 = 100
|
||||
n /= 7 # 14 (truncating integer division)
|
||||
n = div_trunc(n, 7) # 14
|
||||
n -= 4 # 10
|
||||
if n == 10 {
|
||||
return 1
|
||||
@@ -28,7 +27,7 @@ main func() i32 {
|
||||
total += 10 # 10
|
||||
total -= 3 # 7
|
||||
total *= 4 # 28
|
||||
total /= 2 # 14
|
||||
total = div_trunc(total, 2) # 14
|
||||
|
||||
# binary operators honour precedence: 14 + (2 * 3) - 4 == 16
|
||||
total = total + 2 * 3 - 4
|
||||
|
||||
Reference in New Issue
Block a user