1 fn max_value() -> int {
5 fn min_value() -> int {
6 ret (-1 << (sys::size_of::<int>() * 8u as int - 1)) as int;
10 pure fn add(x: int, y: int) -> int { ret x + y; }
12 pure fn sub(x: int, y: int) -> int { ret x - y; }
14 pure fn mul(x: int, y: int) -> int { ret x * y; }
16 pure fn div(x: int, y: int) -> int { ret x / y; }
18 pure fn rem(x: int, y: int) -> int { ret x % y; }
20 pure fn lt(x: int, y: int) -> bool { ret x < y; }
22 pure fn le(x: int, y: int) -> bool { ret x <= y; }
24 pure fn eq(x: int, y: int) -> bool { ret x == y; }
26 pure fn ne(x: int, y: int) -> bool { ret x != y; }
28 pure fn ge(x: int, y: int) -> bool { ret x >= y; }
30 pure fn gt(x: int, y: int) -> bool { ret x > y; }
32 pure fn positive(x: int) -> bool { ret x > 0; }
34 pure fn negative(x: int) -> bool { ret x < 0; }
36 pure fn nonpositive(x: int) -> bool { ret x <= 0; }
38 pure fn nonnegative(x: int) -> bool { ret x >= 0; }
41 // FIXME: Make sure this works with negative integers.
42 fn hash(x: int) -> uint { ret x as uint; }
44 fn eq_alias(x: int, y: int) -> bool { ret x == y; }
46 fn range(lo: int, hi: int, it: block(int)) {
47 while lo < hi { it(lo); lo += 1; }
50 fn parse_buf(buf: [u8], radix: uint) -> int {
51 if vec::len::<u8>(buf) == 0u {
52 log_err "parse_buf(): buf is empty";
55 let i = vec::len::<u8>(buf) - 1u;
57 if buf[0] == ('-' as u8) {
63 n += (buf[i] - ('0' as u8) as int) * power;
64 power *= radix as int;
71 fn from_str(s: str) -> int { parse_buf(str::bytes(s), 10u) }
73 fn to_str(n: int, radix: uint) -> str {
74 assert (0u < radix && radix <= 16u);
76 "-" + uint::to_str(-n as uint, radix)
77 } else { uint::to_str(n as uint, radix) };
79 fn str(i: int) -> str { ret to_str(i, 10u); }
81 fn pow(base: int, exponent: uint) -> int {
82 if exponent == 0u { ret 1; } //Not mathemtically true if [base == 0]
83 if base == 0 { ret 0; }
84 let my_pow = exponent;
86 let multiplier = base;
88 if my_pow % 2u == 1u {
92 multiplier *= multiplier;
99 // indent-tabs-mode: nil
101 // buffer-file-coding-system: utf-8-unix
102 // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";