Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Last active December 11, 2015 14:28
Show Gist options
  • Select an option

  • Save Kimundi/4614018 to your computer and use it in GitHub Desktop.

Select an option

Save Kimundi/4614018 to your computer and use it in GitHub Desktop.
type T = int;
priv fn ioprintnum(num: T) {
let mut buf: ~[u8] = ~[];
let mut deccum = if num < 0 as T {-num} else {num};
loop {
let d = deccum % 10 as T;
deccum /= 10 as T;
buf.push(match d {
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 => '0' as u8 + d as u8,
_ if d > 9 => fail ~"too high",
_ if d < 0 => fail ~"too low",
_ => fail
});
if !(deccum > 0 as T) { break; }
}
if num < 0 {
buf.push('-' as u8);
}
vec::reverse(buf);
io::print(str::from_bytes(buf));
io::print("\n");
}
fn main() {
let mut i: T = 1;
loop {
ioprintnum(i);
i *= 2 as T;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment