Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate num_bigint; // 0.2.2
- use std::ops::Add;
- use num_bigint::BigInt;
- fn fib<T: Add<Output=T> + Clone>(one: T, n: usize) -> T {
- let mut t = (one.clone(), one);
- for _ in 0 .. n {
- t = (t.0.clone() + t.1, t.0);
- }
- t.1
- }
- fn main() {
- println!("f32: {}", fib(1f32, 7));
- println!("fu8: {}", fib(1u8, 7));
- println!("usize: {}", fib(1usize, 7));
- println!("BigInt: {}", fib(BigInt::from(1), 700));
- }
Add Comment
Please, Sign In to add comment