Numeric behavior

Integer division, modulo semantics, division by zero, float-to-int conversion, and overflow promotion.

Summary

/ truncates toward zero for integers (so -7 / 2 is -3, not -4). // is floor division, which rounds toward negative infinity. Modulo sign follows the dividend. Division by zero raises a catchable runtime error; guard the divisor or wrap in try/catch. int(x) truncates toward zero. Integers automatically promote to arbitrary-precision bigints on overflow, with no action required.

Canonical

Integer Division: Truncation Toward Zero

println(7 / 3)                   -- 2
println((-7) / 3)                -- -2  (toward zero, NOT -3)
println(7 / (-3))                -- -2

Floor Division: Toward Negative Infinity

println(5 // 2)                  -- 2
println(-7 // 2)                 -- -4
println(7 // -2)                 -- -4

Modulo: Sign Follows Dividend

println(7 % 3)                   -- 1
println((-7) % 3)                -- -1  (sign follows -7)
println(7 % (-3))                -- 1   (sign follows 7)

Division by Zero

Dividing by zero raises a catchable runtime error:

try { let d = 10 / 0 } catch e { println(e.kind) }   -- "division by zero"
try { let m = 10 % 0 } catch e { println(e.kind) }   -- "modulo by zero"

Guard the divisor or wrap the operation in try/catch.

Float-to-Integer Conversion

int(x) truncates toward zero (not rounding):

println(int(3.9))                -- 3
println(int(-3.9))               -- -3

Integer Overflow

Automatically promotes to arbitrary-precision bigint:

let max = 9223372036854775807    -- 2^63 - 1
println(max + 1)                 -- 9223372036854775808 (bigint)
println(2 ** 100)                -- 1267650600228229401496703205376