Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 580 Bytes

big-integers.zh.md

File metadata and controls

29 lines (22 loc) · 580 Bytes

大整数

[![num-badge]][num] [![cat-science-badge]][cat-science]

可以使用BigInt,计算超过 128 位的整数。

extern crate num;

use num::bigint::{BigInt, ToBigInt};

fn factorial(x: i32) -> BigInt {
    if let Some(mut factorial) = 1.to_bigint() {
        for i in 1..(x+1) {
            factorial = factorial * i;
        }
        factorial
    }
    else {
        panic!("Failed to calculate factorial!");
    }
}

fn main() {
    println!("{}! equals {}", 100, factorial(100));
}