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
_groups digits so big numbers stay readable; it changes nothing.0xffis hexadecimal,0o644octal (as file permissions are written) and0b1010binary.- Dividing two
Ints gives anInt:7 / 2is3, 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.