diff options
| author | Marijn Haverbeke <[email protected]> | 2011-05-06 22:13:13 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <[email protected]> | 2011-05-06 22:51:19 +0200 |
| commit | a3ec0b1f643d00b9418e4884bd7caa07bf052201 (patch) | |
| tree | 82000510ac9c9cf3f0c7cf4ae5f3c6b123b559cb /src/lib/Int.rs | |
| parent | Register new snapshots. (diff) | |
| download | rust-a3ec0b1f643d00b9418e4884bd7caa07bf052201.tar.xz rust-a3ec0b1f643d00b9418e4884bd7caa07bf052201.zip | |
Rename std modules to be camelcased
(Have fun mergining your stuff with this.)
Diffstat (limited to 'src/lib/Int.rs')
| -rw-r--r-- | src/lib/Int.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/Int.rs b/src/lib/Int.rs new file mode 100644 index 00000000..59fb507f --- /dev/null +++ b/src/lib/Int.rs @@ -0,0 +1,62 @@ + +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; } + +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; } + +iter range(int lo, int hi) -> int { + let int lo_ = lo; + while (lo_ < hi) { + put lo_; + lo_ += 1; + } +} + +fn to_str(int n, uint radix) -> str +{ + assert (0u < radix && radix <= 16u); + if (n < 0) { + ret "-" + UInt.to_str((-n) as uint, radix); + } else { + ret UInt.to_str(n as uint, radix); + } +} + +fn pow(int base, uint exponent) -> int { + + if (exponent == 0u) { + ret 1; + } else if (base == 0) { + ret 0; + } else { + auto accum = base; + auto count = exponent; + while (count > 1u) { + accum *= base; + count -= 1u; + } + ret accum; + } +} + +// Local Variables: +// mode: rust; +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: |