aboutsummaryrefslogtreecommitdiff
path: root/src/lib/_int.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-08-20 11:40:59 -0700
committerGraydon Hoare <[email protected]>2010-08-20 11:42:44 -0700
commit9fc4fc6692c6684487eb57c6608ee34ab94dd9f5 (patch)
treecddbecd3d439f36d27c4549700d25ab3c23f1f52 /src/lib/_int.rs
parentModify session to report errors in an emacs-parser-friendlier way. (diff)
downloadrust-9fc4fc6692c6684487eb57c6608ee34ab94dd9f5.tar.xz
rust-9fc4fc6692c6684487eb57c6608ee34ab94dd9f5.zip
Add _uint module to std, move some code around.
Diffstat (limited to 'src/lib/_int.rs')
-rw-r--r--src/lib/_int.rs58
1 files changed, 2 insertions, 56 deletions
diff --git a/src/lib/_int.rs b/src/lib/_int.rs
index e76c2bf5..396dd331 100644
--- a/src/lib/_int.rs
+++ b/src/lib/_int.rs
@@ -25,66 +25,12 @@ iter range(mutable int lo, int hi) -> int {
}
}
-iter urange(mutable uint lo, uint hi) -> uint {
- while (lo < hi) {
- put lo;
- lo += 1u;
- }
-}
-
-fn next_power_of_two(uint n) -> uint {
- // FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
- // world explode.
- let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
- let uint tmp = n - 1u;
- let uint shift = 1u;
- while (shift <= halfbits) {
- tmp |= tmp >> shift;
- shift <<= 1u;
- }
- ret tmp + 1u;
-}
-
-fn uto_str(mutable uint n, uint radix) -> str
-{
- check (0u < radix && radix <= 16u);
- fn digit(uint n) -> str {
- alt (n) {
- case (0u) { ret "0"; }
- case (1u) { ret "1"; }
- case (2u) { ret "2"; }
- case (3u) { ret "3"; }
- case (4u) { ret "4"; }
- case (5u) { ret "5"; }
- case (6u) { ret "6"; }
- case (7u) { ret "7"; }
- case (8u) { ret "8"; }
- case (9u) { ret "9"; }
- case (10u) { ret "a"; }
- case (11u) { ret "b"; }
- case (12u) { ret "c"; }
- case (13u) { ret "d"; }
- case (14u) { ret "e"; }
- case (15u) { ret "f"; }
- }
- }
-
- if (n == 0u) { ret "0"; }
-
- let str s = "";
- while (n > 0u) {
- s = digit(n % radix) + s;
- n /= radix;
- }
- ret s;
-}
-
fn to_str(mutable int n, uint radix) -> str
{
check (0u < radix && radix <= 16u);
if (n < 0) {
- ret "-" + uto_str((-n) as uint, radix);
+ ret "-" + _uint.to_str((-n) as uint, radix);
} else {
- ret uto_str(n as uint, radix);
+ ret _uint.to_str(n as uint, radix);
}
}