@@ -341,89 +341,60 @@ pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String {
341
341
r
342
342
}
343
343
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]`.
369
344
#[ inline]
370
- pub fn from_str_hex ( num : & str ) -> Option < f64 > {
371
- strconv:: from_str_radix_float ( num, 16 u)
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 )
372
348
}
373
349
374
350
impl FromStr for f64 {
375
351
/// Convert a string in base 10 to a float.
376
352
/// Accepts an optional decimal exponent.
377
353
///
378
- /// This function accepts strings such as
354
+ /// This function accepts strings such as:
379
355
///
380
356
/// * '3.14'
381
- /// * '+3.14', equivalent to '3.14'
382
357
/// * '-3.14'
383
358
/// * '2.5E10', or equivalently, '2.5e10'
384
359
/// * '2.5E-10'
385
360
/// * '.' (understood as 0)
386
361
/// * '5.'
387
362
/// * '.5', or, equivalently, '0.5'
388
- /// * '+inf', ' inf', '-inf', 'NaN'
363
+ /// * inf', '-inf', 'NaN'
389
364
///
390
365
/// Leading and trailing whitespace represent an error.
391
366
///
392
367
/// # Arguments
393
368
///
394
- /// * num - A string
369
+ /// * src - A string
395
370
///
396
371
/// # Return value
397
372
///
398
373
/// `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 `.
400
375
#[ inline]
401
- fn from_str ( val : & str ) -> Option < f64 > {
402
- strconv:: from_str_radix_float ( val , 10 u)
376
+ fn from_str ( src : & str ) -> Option < f64 > {
377
+ strconv:: from_str_radix_float ( src , 10 u)
403
378
}
404
379
}
405
380
406
381
impl num:: FromStrRadix for f64 {
407
382
/// Convert a string in a given base to a float.
408
383
///
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
- ///
413
384
/// Leading and trailing whitespace represent an error.
414
385
///
415
386
/// # Arguments
416
387
///
417
- /// * num - A string
388
+ /// * src - A string
418
389
/// * radix - The base to use. Must lie in the range [2 .. 36]
419
390
///
420
391
/// # Return value
421
392
///
422
393
/// `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 `.
424
395
#[ 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)
427
398
}
428
399
}
429
400
@@ -709,8 +680,8 @@ mod tests {
709
680
fn test_ldexp ( ) {
710
681
// We have to use from_str until base-2 exponents
711
682
// 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 ( ) ;
714
685
assert_eq ! ( FloatMath :: ldexp( 1f64 , -123 ) , f1) ;
715
686
assert_eq ! ( FloatMath :: ldexp( 1f64 , -111 ) , f2) ;
716
687
@@ -729,8 +700,8 @@ mod tests {
729
700
fn test_frexp ( ) {
730
701
// We have to use from_str until base-2 exponents
731
702
// 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 ( ) ;
734
705
let ( x1, exp1) = f1. frexp ( ) ;
735
706
let ( x2, exp2) = f2. frexp ( ) ;
736
707
assert_eq ! ( ( x1, exp1) , ( 0.5f64 , -122 ) ) ;
0 commit comments