Reputation: 2890
When I try to do 10 power 100, I get
thread 'main' panicked at 'attempt to multiply with overflow', shorter.rs:33
note: Run with `RUST_BACKTRACE=1` for a backtrace.
which is normal because 10^100 is greater than 2^64 (and even 2^128).
Upvotes: 11
Views: 8489
Reputation: 1101
If you're definitely only working with integers you can use either BigInt
or BigUint
from the big_int crate. An example usage could be:
extern crate num_bigint;
use num_bigint::{BigInt, Sign};
fn main() {
let x = BigInt::new(Sign::Plus, vec![1, 0]);
println!(num::pow(x, 100).to_str_radix(10));
}
Upvotes: 11