rm obsolete float to_str_radix free functions

This commit is contained in:
Daniel Micay 2013-08-18 12:23:48 -04:00
parent 46fc549fa9
commit 0ba8ccdaee
3 changed files with 53 additions and 74 deletions

View File

@ -740,29 +740,6 @@ pub fn to_str_hex(num: f32) -> ~str {
r
}
///
/// 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: f32, rdx: uint) -> ~str {
let (r, special) = strconv::float_to_str_common(
num, rdx, 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
@ -816,9 +793,25 @@ impl to_str::ToStr for f32 {
}
impl num::ToStrRadix for f32 {
/// 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, rdx: uint) -> ~str {
to_str_radix(*self, rdx)
let (r, special) = strconv::float_to_str_common(
*self, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!("number has a special value, \
try to_str_radix_special() if those are expected") }
r
}
}

View File

@ -787,29 +787,6 @@ pub fn to_str_hex(num: f64) -> ~str {
r
}
///
/// 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: f64, rdx: uint) -> ~str {
let (r, special) = strconv::float_to_str_common(
num, rdx, 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
@ -863,9 +840,25 @@ impl to_str::ToStr for f64 {
}
impl num::ToStrRadix for f64 {
/// 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, rdx: uint) -> ~str {
to_str_radix(*self, rdx)
let (r, special) = strconv::float_to_str_common(
*self, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!("number has a special value, \
try to_str_radix_special() if those are expected") }
r
}
}

View File

@ -111,29 +111,6 @@ pub fn to_str_hex(num: float) -> ~str {
r
}
///
/// 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]