Skip to content

Commit 8bd37e6

Browse files
committed
Deprecate {f32, f64}::from_str_hex
This is now covered by `FromStrRadix::from_str_radix`
1 parent 01ded58 commit 8bd37e6

File tree

2 files changed

+27
-80
lines changed

2 files changed

+27
-80
lines changed

src/libstd/num/f32.rs

+10-34
Original file line numberDiff line numberDiff line change
@@ -333,34 +333,10 @@ pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String {
333333
r
334334
}
335335

336-
/// Convert a string in base 16 to a float.
337-
/// Accepts an optional binary exponent.
338-
///
339-
/// This function accepts strings such as
340-
///
341-
/// * 'a4.fe'
342-
/// * '+a4.fe', equivalent to 'a4.fe'
343-
/// * '-a4.fe'
344-
/// * '2b.aP128', or equivalently, '2b.ap128'
345-
/// * '2b.aP-128'
346-
/// * '.' (understood as 0)
347-
/// * 'c.'
348-
/// * '.c', or, equivalently, '0.c'
349-
/// * '+inf', 'inf', '-inf', 'NaN'
350-
///
351-
/// Leading and trailing whitespace represent an error.
352-
///
353-
/// # Arguments
354-
///
355-
/// * num - A string
356-
///
357-
/// # Return value
358-
///
359-
/// `None` if the string did not represent a valid number. Otherwise,
360-
/// `Some(n)` where `n` is the floating-point number represented by `[num]`.
361336
#[inline]
337+
#[deprecated="Use `FromStrRadix::from_str_radix(src, 16)`"]
362338
pub fn from_str_hex(src: &str) -> Option<f32> {
363-
strconv::from_str_radix_float(src, 16u)
339+
strconv::from_str_radix_float(src, 16)
364340
}
365341

366342
impl FromStr for f32 {
@@ -383,12 +359,12 @@ impl FromStr for f32 {
383359
///
384360
/// # Arguments
385361
///
386-
/// * num - A string
362+
/// * src - A string
387363
///
388364
/// # Return value
389365
///
390366
/// `None` if the string did not represent a valid number. Otherwise,
391-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
367+
/// `Some(n)` where `n` is the floating-point number represented by `src`.
392368
#[inline]
393369
fn from_str(src: &str) -> Option<f32> {
394370
strconv::from_str_radix_float(src, 10u)
@@ -406,13 +382,13 @@ impl num::FromStrRadix for f32 {
406382
///
407383
/// # Arguments
408384
///
409-
/// * num - A string
385+
/// * src - A string
410386
/// * radix - The base to use. Must lie in the range [2 .. 36]
411387
///
412388
/// # Return value
413389
///
414390
/// `None` if the string did not represent a valid number. Otherwise,
415-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
391+
/// `Some(n)` where `n` is the floating-point number represented by `src`.
416392
#[inline]
417393
fn from_str_radix(src: &str, radix: uint) -> Option<f32> {
418394
strconv::from_str_radix_float(src, radix)
@@ -707,8 +683,8 @@ mod tests {
707683
fn test_ldexp() {
708684
// We have to use from_str until base-2 exponents
709685
// are supported in floating-point literals
710-
let f1: f32 = from_str_hex("1p-123").unwrap();
711-
let f2: f32 = from_str_hex("1p-111").unwrap();
686+
let f1: f32 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
687+
let f2: f32 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
712688
assert_eq!(FloatMath::ldexp(1f32, -123), f1);
713689
assert_eq!(FloatMath::ldexp(1f32, -111), f2);
714690

@@ -727,8 +703,8 @@ mod tests {
727703
fn test_frexp() {
728704
// We have to use from_str until base-2 exponents
729705
// are supported in floating-point literals
730-
let f1: f32 = from_str_hex("1p-123").unwrap();
731-
let f2: f32 = from_str_hex("1p-111").unwrap();
706+
let f1: f32 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
707+
let f2: f32 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
732708
let (x1, exp1) = f1.frexp();
733709
let (x2, exp2) = f2.frexp();
734710
assert_eq!((x1, exp1), (0.5f32, -122));

src/libstd/num/f64.rs

+17-46
Original file line numberDiff line numberDiff line change
@@ -341,89 +341,60 @@ pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String {
341341
r
342342
}
343343

344-
/// Convert a string in base 16 to a float.
345-
/// Accepts an optional binary exponent.
346-
///
347-
/// This function accepts strings such as
348-
///
349-
/// * 'a4.fe'
350-
/// * '+a4.fe', equivalent to 'a4.fe'
351-
/// * '-a4.fe'
352-
/// * '2b.aP128', or equivalently, '2b.ap128'
353-
/// * '2b.aP-128'
354-
/// * '.' (understood as 0)
355-
/// * 'c.'
356-
/// * '.c', or, equivalently, '0.c'
357-
/// * '+inf', 'inf', '-inf', 'NaN'
358-
///
359-
/// Leading and trailing whitespace represent an error.
360-
///
361-
/// # Arguments
362-
///
363-
/// * num - A string
364-
///
365-
/// # Return value
366-
///
367-
/// `None` if the string did not represent a valid number. Otherwise,
368-
/// `Some(n)` where `n` is the floating-point number represented by `[num]`.
369344
#[inline]
370-
pub fn from_str_hex(num: &str) -> Option<f64> {
371-
strconv::from_str_radix_float(num, 16u)
345+
#[deprecated="Use `FromStrRadix::from_str_radix(src, 16)`"]
346+
pub fn from_str_hex(src: &str) -> Option<f64> {
347+
strconv::from_str_radix_float(src, 16)
372348
}
373349

374350
impl FromStr for f64 {
375351
/// Convert a string in base 10 to a float.
376352
/// Accepts an optional decimal exponent.
377353
///
378-
/// This function accepts strings such as
354+
/// This function accepts strings such as:
379355
///
380356
/// * '3.14'
381-
/// * '+3.14', equivalent to '3.14'
382357
/// * '-3.14'
383358
/// * '2.5E10', or equivalently, '2.5e10'
384359
/// * '2.5E-10'
385360
/// * '.' (understood as 0)
386361
/// * '5.'
387362
/// * '.5', or, equivalently, '0.5'
388-
/// * '+inf', 'inf', '-inf', 'NaN'
363+
/// * inf', '-inf', 'NaN'
389364
///
390365
/// Leading and trailing whitespace represent an error.
391366
///
392367
/// # Arguments
393368
///
394-
/// * num - A string
369+
/// * src - A string
395370
///
396371
/// # Return value
397372
///
398373
/// `none` if the string did not represent a valid number. Otherwise,
399-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
374+
/// `Some(n)` where `n` is the floating-point number represented by `src`.
400375
#[inline]
401-
fn from_str(val: &str) -> Option<f64> {
402-
strconv::from_str_radix_float(val, 10u)
376+
fn from_str(src: &str) -> Option<f64> {
377+
strconv::from_str_radix_float(src, 10u)
403378
}
404379
}
405380

406381
impl num::FromStrRadix for f64 {
407382
/// Convert a string in a given base to a float.
408383
///
409-
/// Due to possible conflicts, this function does **not** accept
410-
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
411-
/// does it recognize exponents of any kind.
412-
///
413384
/// Leading and trailing whitespace represent an error.
414385
///
415386
/// # Arguments
416387
///
417-
/// * num - A string
388+
/// * src - A string
418389
/// * radix - The base to use. Must lie in the range [2 .. 36]
419390
///
420391
/// # Return value
421392
///
422393
/// `None` if the string did not represent a valid number. Otherwise,
423-
/// `Some(n)` where `n` is the floating-point number represented by `num`.
394+
/// `Some(n)` where `n` is the floating-point number represented by `src`.
424395
#[inline]
425-
fn from_str_radix(val: &str, radix: uint) -> Option<f64> {
426-
strconv::from_str_radix_float(val, radix)
396+
fn from_str_radix(src: &str, radix: uint) -> Option<f64> {
397+
strconv::from_str_radix_float(src, radix)
427398
}
428399
}
429400

@@ -709,8 +680,8 @@ mod tests {
709680
fn test_ldexp() {
710681
// We have to use from_str until base-2 exponents
711682
// are supported in floating-point literals
712-
let f1: f64 = from_str_hex("1p-123").unwrap();
713-
let f2: f64 = from_str_hex("1p-111").unwrap();
683+
let f1: f64 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
684+
let f2: f64 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
714685
assert_eq!(FloatMath::ldexp(1f64, -123), f1);
715686
assert_eq!(FloatMath::ldexp(1f64, -111), f2);
716687

@@ -729,8 +700,8 @@ mod tests {
729700
fn test_frexp() {
730701
// We have to use from_str until base-2 exponents
731702
// are supported in floating-point literals
732-
let f1: f64 = from_str_hex("1p-123").unwrap();
733-
let f2: f64 = from_str_hex("1p-111").unwrap();
703+
let f1: f64 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
704+
let f2: f64 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
734705
let (x1, exp1) = f1.frexp();
735706
let (x2, exp2) = f2.frexp();
736707
assert_eq!((x1, exp1), (0.5f64, -122));

0 commit comments

Comments
 (0)