Skip to content

Commit b5d560a

Browse files
author
blake2-ppc
committed
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")
1 parent c135cb2 commit b5d560a

File tree

5 files changed

+190
-216
lines changed

5 files changed

+190
-216
lines changed

src/compiletest/compiletest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern mod extra;
1717

1818
use std::os;
1919
use std::rt;
20-
use std::f64;
2120

2221
use extra::getopts;
2322
use extra::getopts::groups::{optopt, optflag, reqopt};
@@ -131,7 +130,7 @@ pub fn parse_config(args: ~[~str]) -> config {
131130
ratchet_noise_percent:
132131
getopts::opt_maybe_str(matches,
133132
"ratchet-noise-percent").map_move(|s|
134-
f64::from_str(s).unwrap()),
133+
from_str::<f64>(s).unwrap()),
135134
runtool: getopts::opt_maybe_str(matches, "runtool"),
136135
rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
137136
jit: getopts::opt_present(matches, "jit"),

src/librustc/middle/const_eval.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use syntax::visit;
1919
use syntax::visit::Visitor;
2020
use syntax::ast::*;
2121

22-
use std::float;
2322
use std::hashmap::{HashMap, HashSet};
2423

2524
//
@@ -476,9 +475,9 @@ pub fn lit_to_const(lit: &lit) -> const_val {
476475
lit_int(n, _) => const_int(n),
477476
lit_uint(n, _) => const_uint(n),
478477
lit_int_unsuffixed(n) => const_int(n),
479-
lit_float(n, _) => const_float(float::from_str(n).unwrap() as f64),
478+
lit_float(n, _) => const_float(from_str::<float>(n).unwrap() as f64),
480479
lit_float_unsuffixed(n) =>
481-
const_float(float::from_str(n).unwrap() as f64),
480+
const_float(from_str::<float>(n).unwrap() as f64),
482481
lit_nil => const_int(0i64),
483482
lit_bool(b) => const_bool(b)
484483
}

src/libstd/num/f32.rs

+52-60
Original file line numberDiff line numberDiff line change
@@ -822,39 +822,6 @@ impl num::ToStrRadix for f32 {
822822
}
823823
}
824824

825-
///
826-
/// Convert a string in base 10 to a float.
827-
/// Accepts a optional decimal exponent.
828-
///
829-
/// This function accepts strings such as
830-
///
831-
/// * '3.14'
832-
/// * '+3.14', equivalent to '3.14'
833-
/// * '-3.14'
834-
/// * '2.5E10', or equivalently, '2.5e10'
835-
/// * '2.5E-10'
836-
/// * '.' (understood as 0)
837-
/// * '5.'
838-
/// * '.5', or, equivalently, '0.5'
839-
/// * '+inf', 'inf', '-inf', 'NaN'
840-
///
841-
/// Leading and trailing whitespace represent an error.
842-
///
843-
/// # Arguments
844-
///
845-
/// * num - A string
846-
///
847-
/// # Return value
848-
///
849-
/// `none` if the string did not represent a valid number. Otherwise,
850-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
851-
///
852-
#[inline]
853-
pub fn from_str(num: &str) -> Option<f32> {
854-
strconv::from_str_common(num, 10u, true, true, true,
855-
strconv::ExpDec, false, false)
856-
}
857-
858825
///
859826
/// Convert a string in base 16 to a float.
860827
/// Accepts a optional binary exponent.
@@ -888,40 +855,65 @@ pub fn from_str_hex(num: &str) -> Option<f32> {
888855
strconv::ExpBin, false, false)
889856
}
890857

891-
///
892-
/// Convert a string in an given base to a float.
893-
///
894-
/// Due to possible conflicts, this function does **not** accept
895-
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
896-
/// does it recognize exponents of any kind.
897-
///
898-
/// Leading and trailing whitespace represent an error.
899-
///
900-
/// # Arguments
901-
///
902-
/// * num - A string
903-
/// * radix - The base to use. Must lie in the range [2 .. 36]
904-
///
905-
/// # Return value
906-
///
907-
/// `none` if the string did not represent a valid number. Otherwise,
908-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
909-
///
910-
#[inline]
911-
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
912-
strconv::from_str_common(num, rdx, true, true, false,
913-
strconv::ExpNone, false, false)
914-
}
915-
916858
impl FromStr for f32 {
859+
///
860+
/// Convert a string in base 10 to a float.
861+
/// Accepts a optional decimal exponent.
862+
///
863+
/// This function accepts strings such as
864+
///
865+
/// * '3.14'
866+
/// * '+3.14', equivalent to '3.14'
867+
/// * '-3.14'
868+
/// * '2.5E10', or equivalently, '2.5e10'
869+
/// * '2.5E-10'
870+
/// * '.' (understood as 0)
871+
/// * '5.'
872+
/// * '.5', or, equivalently, '0.5'
873+
/// * '+inf', 'inf', '-inf', 'NaN'
874+
///
875+
/// Leading and trailing whitespace represent an error.
876+
///
877+
/// # Arguments
878+
///
879+
/// * num - A string
880+
///
881+
/// # Return value
882+
///
883+
/// `none` if the string did not represent a valid number. Otherwise,
884+
/// `Some(n)` where `n` is the floating-point number represented by `num`.
885+
///
917886
#[inline]
918-
fn from_str(val: &str) -> Option<f32> { from_str(val) }
887+
fn from_str(val: &str) -> Option<f32> {
888+
strconv::from_str_common(val, 10u, true, true, true,
889+
strconv::ExpDec, false, false)
890+
}
919891
}
920892

921893
impl num::FromStrRadix for f32 {
894+
///
895+
/// Convert a string in an given base to a float.
896+
///
897+
/// Due to possible conflicts, this function does **not** accept
898+
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
899+
/// does it recognize exponents of any kind.
900+
///
901+
/// Leading and trailing whitespace represent an error.
902+
///
903+
/// # Arguments
904+
///
905+
/// * num - A string
906+
/// * radix - The base to use. Must lie in the range [2 .. 36]
907+
///
908+
/// # Return value
909+
///
910+
/// `none` if the string did not represent a valid number. Otherwise,
911+
/// `Some(n)` where `n` is the floating-point number represented by `num`.
912+
///
922913
#[inline]
923914
fn from_str_radix(val: &str, rdx: uint) -> Option<f32> {
924-
from_str_radix(val, rdx)
915+
strconv::from_str_common(val, rdx, true, true, false,
916+
strconv::ExpNone, false, false)
925917
}
926918
}
927919

src/libstd/num/f64.rs

+52-60
Original file line numberDiff line numberDiff line change
@@ -869,39 +869,6 @@ impl num::ToStrRadix for f64 {
869869
}
870870
}
871871

872-
///
873-
/// Convert a string in base 10 to a float.
874-
/// Accepts a optional decimal exponent.
875-
///
876-
/// This function accepts strings such as
877-
///
878-
/// * '3.14'
879-
/// * '+3.14', equivalent to '3.14'
880-
/// * '-3.14'
881-
/// * '2.5E10', or equivalently, '2.5e10'
882-
/// * '2.5E-10'
883-
/// * '.' (understood as 0)
884-
/// * '5.'
885-
/// * '.5', or, equivalently, '0.5'
886-
/// * '+inf', 'inf', '-inf', 'NaN'
887-
///
888-
/// Leading and trailing whitespace represent an error.
889-
///
890-
/// # Arguments
891-
///
892-
/// * num - A string
893-
///
894-
/// # Return value
895-
///
896-
/// `none` if the string did not represent a valid number. Otherwise,
897-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
898-
///
899-
#[inline]
900-
pub fn from_str(num: &str) -> Option<f64> {
901-
strconv::from_str_common(num, 10u, true, true, true,
902-
strconv::ExpDec, false, false)
903-
}
904-
905872
///
906873
/// Convert a string in base 16 to a float.
907874
/// Accepts a optional binary exponent.
@@ -935,40 +902,65 @@ pub fn from_str_hex(num: &str) -> Option<f64> {
935902
strconv::ExpBin, false, false)
936903
}
937904

938-
///
939-
/// Convert a string in an given base to a float.
940-
///
941-
/// Due to possible conflicts, this function does **not** accept
942-
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
943-
/// does it recognize exponents of any kind.
944-
///
945-
/// Leading and trailing whitespace represent an error.
946-
///
947-
/// # Arguments
948-
///
949-
/// * num - A string
950-
/// * radix - The base to use. Must lie in the range [2 .. 36]
951-
///
952-
/// # Return value
953-
///
954-
/// `none` if the string did not represent a valid number. Otherwise,
955-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
956-
///
957-
#[inline]
958-
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
959-
strconv::from_str_common(num, rdx, true, true, false,
960-
strconv::ExpNone, false, false)
961-
}
962-
963905
impl FromStr for f64 {
906+
///
907+
/// Convert a string in base 10 to a float.
908+
/// Accepts a optional decimal exponent.
909+
///
910+
/// This function accepts strings such as
911+
///
912+
/// * '3.14'
913+
/// * '+3.14', equivalent to '3.14'
914+
/// * '-3.14'
915+
/// * '2.5E10', or equivalently, '2.5e10'
916+
/// * '2.5E-10'
917+
/// * '.' (understood as 0)
918+
/// * '5.'
919+
/// * '.5', or, equivalently, '0.5'
920+
/// * '+inf', 'inf', '-inf', 'NaN'
921+
///
922+
/// Leading and trailing whitespace represent an error.
923+
///
924+
/// # Arguments
925+
///
926+
/// * num - A string
927+
///
928+
/// # Return value
929+
///
930+
/// `none` if the string did not represent a valid number. Otherwise,
931+
/// `Some(n)` where `n` is the floating-point number represented by `num`.
932+
///
964933
#[inline]
965-
fn from_str(val: &str) -> Option<f64> { from_str(val) }
934+
fn from_str(val: &str) -> Option<f64> {
935+
strconv::from_str_common(val, 10u, true, true, true,
936+
strconv::ExpDec, false, false)
937+
}
966938
}
967939

968940
impl num::FromStrRadix for f64 {
941+
///
942+
/// Convert a string in an given base to a float.
943+
///
944+
/// Due to possible conflicts, this function does **not** accept
945+
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
946+
/// does it recognize exponents of any kind.
947+
///
948+
/// Leading and trailing whitespace represent an error.
949+
///
950+
/// # Arguments
951+
///
952+
/// * num - A string
953+
/// * radix - The base to use. Must lie in the range [2 .. 36]
954+
///
955+
/// # Return value
956+
///
957+
/// `none` if the string did not represent a valid number. Otherwise,
958+
/// `Some(n)` where `n` is the floating-point number represented by `num`.
959+
///
969960
#[inline]
970961
fn from_str_radix(val: &str, rdx: uint) -> Option<f64> {
971-
from_str_radix(val, rdx)
962+
strconv::from_str_common(val, rdx, true, true, false,
963+
strconv::ExpNone, false, false)
972964
}
973965
}
974966

0 commit comments

Comments
 (0)