Skip to content
Kavachकवच

Data Types: BigInt

● Beginner3 min

BigInt is a whole number of any size, worked out exactly.

fn main() {
    let d = 234234 * 23424293429030023
    print(d)
    print(2 ** 100)
    let total: BigInt = 1
    for i in 1..=25 {
        total *= BigInt(i)
    }
    print(total)
}

The program ran and printed:

kavach run bigint.kav

5486765947055418407382126765060022822940149670320537615511210043330985984000000
bigint.kav: Kavach code, then what running it prints

A constant too big for an Int, like the first two above, is a BigInt by itself. Turn an Int into one with BigInt(i). It is slower than Int, so use it only when numbers may really get that large.

What Kavach does for you

  • Big numbers just work

    A constant too big for Int, like 2 ** 100, becomes a BigInt with the exact value. No overflow, no library.

    decision 0041