Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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")
  • Loading branch information
blake2-ppc committed Sep 18, 2013
1 parent c135cb2 commit b5d560a
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 216 deletions.
3 changes: 1 addition & 2 deletions src/compiletest/compiletest.rs
Expand Up @@ -17,7 +17,6 @@ extern mod extra;

use std::os;
use std::rt;
use std::f64;

use extra::getopts;
use extra::getopts::groups::{optopt, optflag, reqopt};
Expand Down Expand Up @@ -131,7 +130,7 @@ pub fn parse_config(args: ~[~str]) -> config {
ratchet_noise_percent:
getopts::opt_maybe_str(matches,
"ratchet-noise-percent").map_move(|s|
f64::from_str(s).unwrap()),
from_str::<f64>(s).unwrap()),
runtool: getopts::opt_maybe_str(matches, "runtool"),
rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
jit: getopts::opt_present(matches, "jit"),
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -19,7 +19,6 @@ use syntax::visit;
use syntax::visit::Visitor;
use syntax::ast::*;

use std::float;
use std::hashmap::{HashMap, HashSet};

//
Expand Down Expand Up @@ -476,9 +475,9 @@ pub fn lit_to_const(lit: &lit) -> const_val {
lit_int(n, _) => const_int(n),
lit_uint(n, _) => const_uint(n),
lit_int_unsuffixed(n) => const_int(n),
lit_float(n, _) => const_float(float::from_str(n).unwrap() as f64),
lit_float(n, _) => const_float(from_str::<float>(n).unwrap() as f64),
lit_float_unsuffixed(n) =>
const_float(float::from_str(n).unwrap() as f64),
const_float(from_str::<float>(n).unwrap() as f64),
lit_nil => const_int(0i64),
lit_bool(b) => const_bool(b)
}
Expand Down
112 changes: 52 additions & 60 deletions src/libstd/num/f32.rs
Expand Up @@ -822,39 +822,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.
Expand Down Expand Up @@ -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)
}
}

Expand Down
112 changes: 52 additions & 60 deletions src/libstd/num/f64.rs
Expand Up @@ -869,39 +869,6 @@ impl num::ToStrRadix for f64 {
}
}

///
/// 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<f64> {
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.
Expand Down Expand Up @@ -935,40 +902,65 @@ pub fn from_str_hex(num: &str) -> Option<f64> {
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<f64> {
strconv::from_str_common(num, rdx, true, true, false,
strconv::ExpNone, false, false)
}

impl FromStr for f64 {
///
/// 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<f64> { from_str(val) }
fn from_str(val: &str) -> Option<f64> {
strconv::from_str_common(val, 10u, true, true, true,
strconv::ExpDec, false, false)
}
}

impl num::FromStrRadix for f64 {
///
/// 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<f64> {
from_str_radix(val, rdx)
strconv::from_str_common(val, rdx, true, true, false,
strconv::ExpNone, false, false)
}
}

Expand Down

5 comments on commit b5d560a

@bors
Copy link
Contributor

@bors bors commented on b5d560a Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on b5d560a Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging blake2-ppc/rust/float-from-str = b5d560a into auto

@bors
Copy link
Contributor

@bors bors commented on b5d560a Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blake2-ppc/rust/float-from-str = b5d560a merged ok, testing candidate = e02313a

@bors
Copy link
Contributor

@bors bors commented on b5d560a Sep 18, 2013

@bors
Copy link
Contributor

@bors bors commented on b5d560a Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e02313a

Please sign in to comment.