SHARE
TWEET

Untitled

a guest Feb 17th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate num_bigint; // 0.2.2
  2.  
  3. use std::ops::Add;
  4. use num_bigint::BigInt;
  5.  
  6. fn fib<T: Add<Output=T> + Clone>(one: T, n: usize) -> T {
  7.     let mut t = (one.clone(), one);
  8.     for _ in 0 .. n {
  9.         t = (t.0.clone() + t.1, t.0);
  10.     }
  11.     t.1
  12. }
  13.  
  14. fn main() {
  15.     println!("f32: {}", fib(1f32, 7));
  16.     println!("fu8: {}", fib(1u8, 7));
  17.     println!("usize: {}", fib(1usize, 7));
  18.     println!("BigInt: {}", fib(BigInt::from(1), 700));
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top