Skip to content

Instantly share code, notes, and snippets.

@5nyper
Created January 12, 2015 18:44
Show Gist options
  • Save 5nyper/0f7a5a5291aaac70496f to your computer and use it in GitHub Desktop.
Save 5nyper/0f7a5a5291aaac70496f to your computer and use it in GitHub Desktop.
Overflow
/// So I have this code snippet
extern crate num;
use num::{BigUint, Zero, One};
use std::mem::replace;
fn main() {
let mut f0: BigUint = 100;
let mut f1: BigUint = 100;
for _ in (0..100) {
if f0 <= 1 {
break;
}
f0 -= 1;
// This is a low cost way of swapping f0 with f1 and f1 with f2.
f1 *= f0;
}
println!("{}", f1);
}
/// I used BigInt because if I used i64's I would get an overflow error, but the problem is
/// That I cant use binary operations with BigInts, is there a workaround or another soltuion
/// to this tragic predicament??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment