当我尝试做10次100时,我得到了
thread 'main' panicked at 'attempt to multiply with overflow', shorter.rs:33
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Run Code Online (Sandbox Code Playgroud)
这是正常的,因为10 ^ 100大于2 ^ 64(甚至2 ^ 128).
如果你绝对只能用整数工作,你可以使用BigInt或BigUint从big_int箱.示例用法可以是:
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));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
646 次 |
| 最近记录: |