aboutsummaryrefslogtreecommitdiff
path: root/src/lib/_uint.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-09 17:49:20 -0800
committerGraydon Hoare <[email protected]>2010-11-09 17:50:31 -0800
commita404e542614c0848931544eb0281fd546a62a971 (patch)
tree9b6437fbbc6632d9b68c80df69d74a0e589e9297 /src/lib/_uint.rs
parentImplement a map2() function in std._vec (diff)
downloadrust-a404e542614c0848931544eb0281fd546a62a971.tar.xz
rust-a404e542614c0848931544eb0281fd546a62a971.zip
Teach rustc about const tag value, begin work on trans_copy_ty, make uint's to_str routine less clever and thereby resist overflow.
Diffstat (limited to 'src/lib/_uint.rs')
-rw-r--r--src/lib/_uint.rs28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs
index 0930cadc..7fa4ea02 100644
--- a/src/lib/_uint.rs
+++ b/src/lib/_uint.rs
@@ -59,30 +59,20 @@ fn to_str(mutable uint n, uint radix) -> str
if (n == 0u) { ret "0"; }
- let uint r = 1u;
- if (n > r) {
- while ((r*radix) <= n) {
- r *= radix;
- }
- }
-
let str s = "";
- while (n > 0u) {
-
- auto i = n/r;
-
- n -= (i * r);
- r /= radix;
-
- s += digit(i) as u8;
+ while (n != 0u) {
+ s += digit(n % radix) as u8;
+ n /= radix;
}
- while (r > 0u) {
- s += '0' as u8;
- r /= radix;
+ let str s1 = "";
+ let uint len = _str.byte_len(s);
+ while (len != 0u) {
+ len -= 1u;
+ s1 += s.(len);
}
+ ret s1;
- ret s;
}
// Local Variables: