Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

Integer Overflow

Integer overflow during arithmetic operations MUST cause a runtime panic.

On overflow, the program MUST terminate with exit code 101 and print an error message.

The following operations MAY overflow:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Negation (- unary)
  • Division (/) and remainder (%), exactly when the dividend is the signed type's minimum value and the divisor is -1 (the quotient -MIN is not representable; the remainder operation overflows in the same case even though its mathematical result would be 0)
fn main() -> i32 {
    2147483647 + 1  // Runtime error: integer overflow
}
fn main() -> i32 {
    -2147483648 - 1  // Runtime error: integer overflow
}

Future versions of Rue may provide wrapping arithmetic operations that do not panic on overflow.