]> git.lizzy.rs Git - rust.git/blob - src/lib/int.rs
Merge remote-tracking branch 'graydon/master'
[rust.git] / src / lib / int.rs
1
2
3 pure fn add(x: int, y: int) -> int { ret x + y; }
4
5 pure fn sub(x: int, y: int) -> int { ret x - y; }
6
7 pure fn mul(x: int, y: int) -> int { ret x * y; }
8
9 pure fn div(x: int, y: int) -> int { ret x / y; }
10
11 pure fn rem(x: int, y: int) -> int { ret x % y; }
12
13 pure fn lt(x: int, y: int) -> bool { ret x < y; }
14
15 pure fn le(x: int, y: int) -> bool { ret x <= y; }
16
17 pure fn eq(x: int, y: int) -> bool { ret x == y; }
18
19 pure fn ne(x: int, y: int) -> bool { ret x != y; }
20
21 pure fn ge(x: int, y: int) -> bool { ret x >= y; }
22
23 pure fn gt(x: int, y: int) -> bool { ret x > y; }
24
25 pure fn positive(x: int) -> bool { ret x > 0; }
26
27 pure fn negative(x: int) -> bool { ret x < 0; }
28
29 pure fn nonpositive(x: int) -> bool { ret x <= 0; }
30
31 pure fn nonnegative(x: int) -> bool { ret x >= 0; }
32
33
34 // FIXME: Make sure this works with negative integers.
35 fn hash(x: &int) -> uint { ret x as uint; }
36
37 fn eq_alias(x: &int, y: &int) -> bool { ret x == y; }
38
39 iter range(lo: int, hi: int) -> int {
40     let lo_: int = lo;
41     while lo_ < hi { put lo_; lo_ += 1; }
42 }
43
44 fn to_str(n: int, radix: uint) -> str {
45     assert (0u < radix && radix <= 16u);
46     ret if n < 0 {
47             "-" + uint::to_str(-n as uint, radix)
48         } else { uint::to_str(n as uint, radix) };
49 }
50 fn str(i: int) -> str { ret to_str(i, 10u); }
51
52 fn pow(base: int, exponent: uint) -> int {
53     ret if exponent == 0u {
54             1
55         } else if base == 0 {
56             0
57         } else {
58             let accum = base;
59             let count = exponent;
60             while count > 1u { accum *= base; count -= 1u; }
61             accum
62         };
63 }
64 // Local Variables:
65 // mode: rust;
66 // fill-column: 78;
67 // indent-tabs-mode: nil
68 // c-basic-offset: 4
69 // buffer-file-coding-system: utf-8-unix
70 // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
71 // End: