Guest User

Untitled

a guest
Feb 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment