3 pure fn add(x: int, y: int) -> int { ret x + y; }
5 pure fn sub(x: int, y: int) -> int { ret x - y; }
7 pure fn mul(x: int, y: int) -> int { ret x * y; }
9 pure fn div(x: int, y: int) -> int { ret x / y; }
11 pure fn rem(x: int, y: int) -> int { ret x % y; }
13 pure fn lt(x: int, y: int) -> bool { ret x < y; }
15 pure fn le(x: int, y: int) -> bool { ret x <= y; }
17 pure fn eq(x: int, y: int) -> bool { ret x == y; }
19 pure fn ne(x: int, y: int) -> bool { ret x != y; }
21 pure fn ge(x: int, y: int) -> bool { ret x >= y; }
23 pure fn gt(x: int, y: int) -> bool { ret x > y; }
25 pure fn positive(x: int) -> bool { ret x > 0; }
27 pure fn negative(x: int) -> bool { ret x < 0; }
29 pure fn nonpositive(x: int) -> bool { ret x <= 0; }
31 pure fn nonnegative(x: int) -> bool { ret x >= 0; }
34 // FIXME: Make sure this works with negative integers.
35 fn hash(x: int) -> uint { ret x as uint; }
37 fn eq_alias(x: int, y: int) -> bool { ret x == y; }
39 iter range(lo: int, hi: int) -> int {
41 while lo_ < hi { put lo_; lo_ += 1; }
44 fn parse_buf(buf: [u8], radix: uint) -> int {
45 if vec::len::<u8>(buf) == 0u {
46 log_err "parse_buf(): buf is empty";
49 let i = vec::len::<u8>(buf) - 1u;
51 if buf[0] == ('-' as u8) {
57 n += (buf[i] - ('0' as u8) as int) * power;
58 power *= radix as int;
65 fn from_str(s: str) -> int { parse_buf(str::bytes(s), 10u) }
67 fn to_str(n: int, radix: uint) -> str {
68 assert (0u < radix && radix <= 16u);
70 "-" + uint::to_str(-n as uint, radix)
71 } else { uint::to_str(n as uint, radix) };
73 fn str(i: int) -> str { ret to_str(i, 10u); }
75 fn pow(base: int, exponent: uint) -> int {
76 if exponent == 0u { ret 1; } //Not mathemtically true if [base == 0]
77 if base == 0 { ret 0; }
78 let my_pow = exponent;
80 let multiplier = base;
82 if my_pow % 2u == 1u {
86 multiplier *= multiplier;
93 // indent-tabs-mode: nil
95 // buffer-file-coding-system: utf-8-unix
96 // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";