diff options
| author | blake2-ppc <blake2-ppc> | 2013-09-18 02:17:47 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-09-18 04:02:42 +0200 |
| commit | b5d560a9e09498db5434ea26338a3d2bfc545eee (patch) | |
| tree | 03cdd52c33978d99ddad77c48337f1060eb8cbaf /src/libstd/num/f32.rs | |
| parent | c135cb268355afe77d2ce0313a8d3e20a4e2fdd3 (diff) | |
| download | rust-b5d560a9e09498db5434ea26338a3d2bfc545eee.tar.gz rust-b5d560a9e09498db5434ea26338a3d2bfc545eee.zip | |
std: Remove {float,f64,f32}::from_str in favor of from_str
Like issue #9209, remove float::{from_str, from_str_radix} in favor of
the two corresponding traits. The same for modules f64 and f32.
New usage is
from_str::<float>("1.2e34")
Diffstat (limited to 'src/libstd/num/f32.rs')
| -rw-r--r-- | src/libstd/num/f32.rs | 112 |
1 files changed, 52 insertions, 60 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 0addcce3eb6..1bb488d0278 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -823,39 +823,6 @@ impl num::ToStrRadix for f32 { } /// -/// Convert a string in base 10 to a float. -/// Accepts a optional decimal exponent. -/// -/// This function accepts strings such as -/// -/// * '3.14' -/// * '+3.14', equivalent to '3.14' -/// * '-3.14' -/// * '2.5E10', or equivalently, '2.5e10' -/// * '2.5E-10' -/// * '.' (understood as 0) -/// * '5.' -/// * '.5', or, equivalently, '0.5' -/// * '+inf', 'inf', '-inf', 'NaN' -/// -/// Leading and trailing whitespace represent an error. -/// -/// # Arguments -/// -/// * num - A string -/// -/// # Return value -/// -/// `none` if the string did not represent a valid number. Otherwise, -/// `Some(n)` where `n` is the floating-point number represented by `num`. -/// -#[inline] -pub fn from_str(num: &str) -> Option<f32> { - strconv::from_str_common(num, 10u, true, true, true, - strconv::ExpDec, false, false) -} - -/// /// Convert a string in base 16 to a float. /// Accepts a optional binary exponent. /// @@ -888,40 +855,65 @@ pub fn from_str_hex(num: &str) -> Option<f32> { strconv::ExpBin, false, false) } -/// -/// Convert a string in an given base to a float. -/// -/// Due to possible conflicts, this function does **not** accept -/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor** -/// does it recognize exponents of any kind. -/// -/// Leading and trailing whitespace represent an error. -/// -/// # Arguments -/// -/// * num - A string -/// * radix - The base to use. Must lie in the range [2 .. 36] -/// -/// # Return value -/// -/// `none` if the string did not represent a valid number. Otherwise, -/// `Some(n)` where `n` is the floating-point number represented by `num`. -/// -#[inline] -pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> { - strconv::from_str_common(num, rdx, true, true, false, - strconv::ExpNone, false, false) -} - impl FromStr for f32 { + /// + /// Convert a string in base 10 to a float. + /// Accepts a optional decimal exponent. + /// + /// This function accepts strings such as + /// + /// * '3.14' + /// * '+3.14', equivalent to '3.14' + /// * '-3.14' + /// * '2.5E10', or equivalently, '2.5e10' + /// * '2.5E-10' + /// * '.' (understood as 0) + /// * '5.' + /// * '.5', or, equivalently, '0.5' + /// * '+inf', 'inf', '-inf', 'NaN' + /// + /// Leading and trailing whitespace represent an error. + /// + /// # Arguments + /// + /// * num - A string + /// + /// # Return value + /// + /// `none` if the string did not represent a valid number. Otherwise, + /// `Some(n)` where `n` is the floating-point number represented by `num`. + /// #[inline] - fn from_str(val: &str) -> Option<f32> { from_str(val) } + fn from_str(val: &str) -> Option<f32> { + strconv::from_str_common(val, 10u, true, true, true, + strconv::ExpDec, false, false) + } } impl num::FromStrRadix for f32 { + /// + /// Convert a string in an given base to a float. + /// + /// Due to possible conflicts, this function does **not** accept + /// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor** + /// does it recognize exponents of any kind. + /// + /// Leading and trailing whitespace represent an error. + /// + /// # Arguments + /// + /// * num - A string + /// * radix - The base to use. Must lie in the range [2 .. 36] + /// + /// # Return value + /// + /// `none` if the string did not represent a valid number. Otherwise, + /// `Some(n)` where `n` is the floating-point number represented by `num`. + /// #[inline] fn from_str_radix(val: &str, rdx: uint) -> Option<f32> { - from_str_radix(val, rdx) + strconv::from_str_common(val, rdx, true, true, false, + strconv::ExpNone, false, false) } } |
