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
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, like2 ** 100, becomes aBigIntwith the exact value. No overflow, no library.