2010-07-20 20:03:09 -05:00
|
|
|
import std.sys;
|
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
fn add(int x, int y) -> int { ret x + y; }
|
|
|
|
fn sub(int x, int y) -> int { ret x - y; }
|
|
|
|
fn mul(int x, int y) -> int { ret x * y; }
|
|
|
|
fn div(int x, int y) -> int { ret x / y; }
|
|
|
|
fn rem(int x, int y) -> int { ret x % y; }
|
|
|
|
|
|
|
|
fn lt(int x, int y) -> bool { ret x < y; }
|
|
|
|
fn le(int x, int y) -> bool { ret x <= y; }
|
|
|
|
fn eq(int x, int y) -> bool { ret x == y; }
|
|
|
|
fn ne(int x, int y) -> bool { ret x != y; }
|
|
|
|
fn ge(int x, int y) -> bool { ret x >= y; }
|
|
|
|
fn gt(int x, int y) -> bool { ret x > y; }
|
|
|
|
|
2010-08-03 19:52:35 -05:00
|
|
|
fn positive(int x) -> bool { ret x > 0; }
|
|
|
|
fn negative(int x) -> bool { ret x < 0; }
|
|
|
|
fn nonpositive(int x) -> bool { ret x <= 0; }
|
|
|
|
fn nonnegative(int x) -> bool { ret x >= 0; }
|
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
iter range(mutable int lo, int hi) -> int {
|
|
|
|
while (lo < hi) {
|
|
|
|
put lo;
|
|
|
|
lo += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-29 01:18:51 -05:00
|
|
|
iter urange(mutable uint lo, uint hi) -> uint {
|
|
|
|
while (lo < hi) {
|
|
|
|
put lo;
|
2010-07-27 21:21:51 -05:00
|
|
|
lo += 1u;
|
2010-06-29 01:18:51 -05:00
|
|
|
}
|
|
|
|
}
|
2010-07-20 20:03:09 -05:00
|
|
|
|
|
|
|
fn next_power_of_two(uint n) -> uint {
|
|
|
|
// FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
|
|
|
|
// world explode.
|
2010-07-27 21:21:51 -05:00
|
|
|
let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
|
|
|
|
let uint tmp = n - 1u;
|
|
|
|
let uint shift = 1u;
|
2010-07-20 20:03:09 -05:00
|
|
|
while (shift <= halfbits) {
|
|
|
|
tmp |= tmp >> shift;
|
2010-07-27 21:21:51 -05:00
|
|
|
shift <<= 1u;
|
2010-07-20 20:03:09 -05:00
|
|
|
}
|
2010-07-27 21:21:51 -05:00
|
|
|
ret tmp + 1u;
|
2010-07-20 20:03:09 -05:00
|
|
|
}
|