45 lines
760 B
Plaintext
45 lines
760 B
Plaintext
# Compound assignment (`+=`, `-=`, `*=`, `/=`) and explicit integer division.
|
|
|
|
check_float func() i32 {
|
|
x f64 := 10.0
|
|
x /= 4.0 # 2.5
|
|
x *= 2.0 # 5.0
|
|
x -= 1.0 # 4.0
|
|
x += 0.5 # 4.5
|
|
if x > 4.0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
check_unsigned func() i32 {
|
|
n u32 := 100
|
|
n = divtrunc!(n, 7) # 14
|
|
n -= 4 # 10
|
|
if n == 10 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
main func() i32 {
|
|
total i32 := 0
|
|
total += 10 # 10
|
|
total -= 3 # 7
|
|
total *= 4 # 28
|
|
total = divtrunc!(total, 2) # 14
|
|
|
|
# binary operators honour precedence: 14 + (2 * 3) - 4 == 16
|
|
total = total + 2 * 3 - 4
|
|
|
|
# compound assignment as a while-loop update
|
|
i i32 := 0
|
|
while i < 5 : i += 1 {
|
|
total += 1 # +5 => 21
|
|
}
|
|
|
|
total += check_float() # +1 => 22
|
|
total += check_unsigned() # +1 => 23
|
|
return total
|
|
}
|