diff options
| author | bors <bors@rust-lang.org> | 2013-08-21 01:01:47 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-21 01:01:47 -0700 |
| commit | d4d856b129b7af6e78f1a04d6e942997559d06f8 (patch) | |
| tree | 7954e22e4749955282aef9f81696a6ffaabb1cca /src/libstd/num/float.rs | |
| parent | 48dded95c68b61df02b4c7b175c3219e6d7f4e4d (diff) | |
| parent | 0f6e90a5fd7a19382e3d3028bfcc36eb57135515 (diff) | |
| download | rust-d4d856b129b7af6e78f1a04d6e942997559d06f8.tar.gz rust-d4d856b129b7af6e78f1a04d6e942997559d06f8.zip | |
auto merge of #8582 : thestinger/rust/container, r=thestinger
5f3a637 r=huonw 934a5eb r=thestinger 0f6e90a r=cmr
Diffstat (limited to 'src/libstd/num/float.rs')
| -rw-r--r-- | src/libstd/num/float.rs | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/src/libstd/num/float.rs b/src/libstd/num/float.rs index 486d3562089..20c7adbd62c 100644 --- a/src/libstd/num/float.rs +++ b/src/libstd/num/float.rs @@ -112,29 +112,6 @@ pub fn to_str_hex(num: float) -> ~str { } /// -/// Converts a float to a string in a given radix -/// -/// # Arguments -/// -/// * num - The float value -/// * radix - The base to use -/// -/// # Failure -/// -/// Fails if called on a special value like `inf`, `-inf` or `NaN` due to -/// possible misinterpretation of the result at higher bases. If those values -/// are expected, use `to_str_radix_special()` instead. -/// -#[inline] -pub fn to_str_radix(num: float, radix: uint) -> ~str { - let (r, special) = strconv::float_to_str_common( - num, radix, true, strconv::SignNeg, strconv::DigAll); - if special { fail!("number has a special value, \ - try to_str_radix_special() if those are expected") } - r -} - -/// /// Converts a float to a string in a given radix, and a flag indicating /// whether it's a special value /// @@ -187,9 +164,25 @@ impl to_str::ToStr for float { } impl num::ToStrRadix for float { + /// Converts a float to a string in a given radix + /// + /// # Arguments + /// + /// * num - The float value + /// * radix - The base to use + /// + /// # Failure + /// + /// Fails if called on a special value like `inf`, `-inf` or `NaN` due to + /// possible misinterpretation of the result at higher bases. If those values + /// are expected, use `to_str_radix_special()` instead. #[inline] fn to_str_radix(&self, radix: uint) -> ~str { - to_str_radix(*self, radix) + let (r, special) = strconv::float_to_str_common( + *self, radix, true, strconv::SignNeg, strconv::DigAll); + if special { fail!("number has a special value, \ + try to_str_radix_special() if those are expected") } + r } } @@ -1342,8 +1335,8 @@ mod tests { #[test] pub fn test_to_str_radix() { - assert_eq!(to_str_radix(36., 36u), ~"10"); - assert_eq!(to_str_radix(8.125, 2u), ~"1000.001"); + assert_eq!(36.0f.to_str_radix(36u), ~"10"); + assert_eq!(8.125f.to_str_radix(2u), ~"1000.001"); } #[test] |
