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).
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With