Skip to content
Kavachकवच

Data Types: Int

● Beginner3 min

Int is a whole number, positive or negative, up to about nine quintillion.

fn main() {
    const people = 1_400_000_000
    print(people)
    print(0xff)
    print(0o644)
    print(0b1010)
    print(7 / 2)
    print(7 % 2)
}

The compiler warned, then the program ran:

kavach run int.kav

warning: `7 / 2` is `3`: whole numbers divide to a whole number. Write `7.0 / 2.0` for a fraction, or `7.div_floor(2)` when the whole part is meant (spec 1.8)14000000002554201031
int.kav: Kavach code, then what running it prints
  • _ groups digits so big numbers stay readable; it changes nothing.
  • 0xff is hexadecimal, 0o644 octal (as file permissions are written) and 0b1010 binary.
  • Dividing two Ints gives an Int: 7 / 2 is 3, and the compiler warns, since that is rarely what was meant (see Arithmetic). % gives the remainder.

An Int that goes past its limit stops the program with a message; it never wraps around to a wrong number.