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