diff --git a/doc/rust.md b/doc/rust.md index 7d4ec54aff5..34fd7cf25d6 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -844,7 +844,7 @@ mod quux { pub fn bar() { } pub fn baz() { } } - + pub use quux::foo::*; } ~~~~ @@ -1242,7 +1242,7 @@ trait Num { impl float: Num { static pure fn from_int(n: int) -> float { n as float } } -let x: float = Num::from_int(42); +let x: float = Num::from_int(42); ~~~~ Traits may inherit from other traits. For example, in @@ -1615,7 +1615,7 @@ The following are examples of structure expressions: ~~~~ # struct Point { x: float, y: float } # struct TuplePoint(float, float); -# mod game { pub struct User { name: &str, age: uint, mut score: uint } } +# mod game { pub struct User { name: &str, age: uint, mut score: uint } } # use game; Point {x: 10f, y: 20f}; TuplePoint(10f, 20f); @@ -2812,7 +2812,7 @@ trait Printable { } impl int: Printable { - fn to_str() -> ~str { int::to_str(self, 10) } + fn to_str() -> ~str { int::to_str(self) } } fn print(a: @Printable) { diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 3434ef022da..f814970375a 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -473,7 +473,7 @@ fn stringifier(channel: &DuplexStream<~str, uint>) { let mut value: uint; loop { value = channel.recv(); - channel.send(uint::to_str(value, 10)); + channel.send(uint::to_str(value)); if value == 0 { break; } } } @@ -497,7 +497,7 @@ Here is the code for the parent task: # let mut value: uint; # loop { # value = channel.recv(); -# channel.send(uint::to_str(value, 10u)); +# channel.send(uint::to_str(value)); # if value == 0u { break; } # } # } diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 9a138de3cf3..30f6a727f0a 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -422,6 +422,12 @@ pub pure fn to_str_bytes_common( buf = buf.slice(0, i + 1); } } + } // If exact and trailing '.', just cut that + else { + let max_i = buf.len() - 1; + if buf[max_i] == '.' as u8 { + buf = buf.slice(0, max_i); + } } (buf, false) @@ -678,4 +684,4 @@ pub pure fn from_str_common( ) -> Option { from_str_bytes_common(str::to_bytes(buf), radix, negative, fractional, special, exponent, empty_zero) -} \ No newline at end of file +} diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 165c2a3d9bc..dd25fc36d2d 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -926,7 +926,7 @@ mod tests { let s0 = precise_time_s(); let ns1 = precise_time_ns(); - log(debug, ~"s0=" + float::to_str(s0, 9u) + ~" sec"); + log(debug, ~"s0=" + float::to_str_digits(s0, 9u) + ~" sec"); assert s0 > 0.; let ns0 = (s0 * 1000000000.) as u64; log(debug, ~"ns0=" + u64::str(ns0) + ~" ns"); diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index d401b594c4c..a61d8f01ab7 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -75,12 +75,12 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { let map = map::HashMap(); do timed(&mut results.sequential_strings) { for uint::range(0, num_keys) |i| { - let s = uint::to_str(i, 10); + let s = uint::to_str(i); map.insert(s, i); } for uint::range(0, num_keys) |i| { - let s = uint::to_str(i, 10); + let s = uint::to_str(i); assert map.get(s) == i; } } @@ -90,7 +90,7 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { let map = map::HashMap(); do timed(&mut results.random_strings) { for uint::range(0, num_keys) |i| { - let s = uint::to_str(rng.next() as uint, 10); + let s = uint::to_str(rng.next() as uint); map.insert(s, i); } } @@ -99,11 +99,11 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { { let map = map::HashMap(); for uint::range(0, num_keys) |i| { - map.insert(uint::to_str(i, 10), i); + map.insert(uint::to_str(i), i); } do timed(&mut results.delete_strings) { for uint::range(0, num_keys) |i| { - assert map.remove(uint::to_str(i, 10)); + assert map.remove(uint::to_str(i)); } } } @@ -151,12 +151,12 @@ fn linear_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) let mut map = LinearMap::new(); do timed(&mut results.sequential_strings) { for uint::range(0, num_keys) |i| { - let s = uint::to_str(i, 10); + let s = uint::to_str(i); map.insert(s, i); } for uint::range(0, num_keys) |i| { - let s = uint::to_str(i, 10); + let s = uint::to_str(i); assert map.find(&s).unwrap() == &i; } } @@ -166,7 +166,7 @@ fn linear_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) let mut map = LinearMap::new(); do timed(&mut results.random_strings) { for uint::range(0, num_keys) |i| { - let s = uint::to_str(rng.next() as uint, 10); + let s = uint::to_str(rng.next() as uint); map.insert(s, i); } } @@ -175,11 +175,11 @@ fn linear_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { let mut map = LinearMap::new(); for uint::range(0, num_keys) |i| { - map.insert(uint::to_str(i, 10), i); + map.insert(uint::to_str(i), i); } do timed(&mut results.delete_strings) { for uint::range(0, num_keys) |i| { - assert map.remove(&uint::to_str(i, 10)); + assert map.remove(&uint::to_str(i)); } } } @@ -227,12 +227,12 @@ fn tree_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { let mut map = TreeMap::new(); do timed(&mut results.sequential_strings) { for uint::range(0, num_keys) |i| { - let s = uint::to_str(i, 10); + let s = uint::to_str(i); map.insert(s, i); } for uint::range(0, num_keys) |i| { - let s = uint::to_str(i, 10); + let s = uint::to_str(i); assert map.find(&s).unwrap() == &i; } } @@ -242,7 +242,7 @@ fn tree_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { let mut map = TreeMap::new(); do timed(&mut results.random_strings) { for uint::range(0, num_keys) |i| { - let s = uint::to_str(rng.next() as uint, 10); + let s = uint::to_str(rng.next() as uint); map.insert(s, i); } } @@ -251,11 +251,11 @@ fn tree_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { { let mut map = TreeMap::new(); for uint::range(0, num_keys) |i| { - map.insert(uint::to_str(i, 10), i); + map.insert(uint::to_str(i), i); } do timed(&mut results.delete_strings) { for uint::range(0, num_keys) |i| { - assert map.remove(&uint::to_str(i, 10)); + assert map.remove(&uint::to_str(i)); } } } diff --git a/src/test/bench/core-uint-to-str.rs b/src/test/bench/core-uint-to-str.rs index df4962fb44c..56f616c6f28 100644 --- a/src/test/bench/core-uint-to-str.rs +++ b/src/test/bench/core-uint-to-str.rs @@ -21,7 +21,7 @@ fn main() { let n = uint::from_str(args[1]).get(); for uint::range(0u, n) |i| { - let x = uint::to_str(i, 10u); + let x = uint::to_str(i); log(debug, x); } } diff --git a/src/test/run-pass/core-export-f64-sqrt.rs b/src/test/run-pass/core-export-f64-sqrt.rs index 37f605d9320..d7ac91fe75c 100644 --- a/src/test/run-pass/core-export-f64-sqrt.rs +++ b/src/test/run-pass/core-export-f64-sqrt.rs @@ -14,5 +14,5 @@ pub fn main() { let digits: uint = 10 as uint; - ::core::io::println(float::to_str(f64::sqrt(42.0f64) as float, digits)); + ::core::io::println(float::to_str_digits(f64::sqrt(42.0f64) as float, digits)); }