@@ -341,92 +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_common ( num , 16 u , true , true , true ,
372- strconv:: ExpBin , false , false )
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 )
373348}
374349
375350impl FromStr for f64 {
376351 /// Convert a string in base 10 to a float.
377352 /// Accepts an optional decimal exponent.
378353 ///
379- /// This function accepts strings such as
354+ /// This function accepts strings such as:
380355 ///
381356 /// * '3.14'
382- /// * '+3.14', equivalent to '3.14'
383357 /// * '-3.14'
384358 /// * '2.5E10', or equivalently, '2.5e10'
385359 /// * '2.5E-10'
386360 /// * '.' (understood as 0)
387361 /// * '5.'
388362 /// * '.5', or, equivalently, '0.5'
389- /// * '+inf', ' inf', '-inf', 'NaN'
363+ /// * inf', '-inf', 'NaN'
390364 ///
391365 /// Leading and trailing whitespace represent an error.
392366 ///
393367 /// # Arguments
394368 ///
395- /// * num - A string
369+ /// * src - A string
396370 ///
397371 /// # Return value
398372 ///
399373 /// `none` if the string did not represent a valid number. Otherwise,
400- /// `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 `.
401375 #[ inline]
402- fn from_str ( val : & str ) -> Option < f64 > {
403- strconv:: from_str_common ( val, 10 u, true , true , true ,
404- strconv:: ExpDec , false , false )
376+ fn from_str ( src : & str ) -> Option < f64 > {
377+ strconv:: from_str_radix_float ( src, 10 u)
405378 }
406379}
407380
408381impl num:: FromStrRadix for f64 {
409382 /// Convert a string in a given base to a float.
410383 ///
411- /// Due to possible conflicts, this function does **not** accept
412- /// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
413- /// does it recognize exponents of any kind.
414- ///
415384 /// Leading and trailing whitespace represent an error.
416385 ///
417386 /// # Arguments
418387 ///
419- /// * num - A string
388+ /// * src - A string
420389 /// * radix - The base to use. Must lie in the range [2 .. 36]
421390 ///
422391 /// # Return value
423392 ///
424393 /// `None` if the string did not represent a valid number. Otherwise,
425- /// `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 `.
426395 #[ inline]
427- fn from_str_radix ( val : & str , rdx : uint ) -> Option < f64 > {
428- strconv:: from_str_common ( val, rdx, true , true , false ,
429- strconv:: ExpNone , false , false )
396+ fn from_str_radix ( src : & str , radix : uint ) -> Option < f64 > {
397+ strconv:: from_str_radix_float ( src, radix)
430398 }
431399}
432400
@@ -712,8 +680,8 @@ mod tests {
712680 fn test_ldexp ( ) {
713681 // We have to use from_str until base-2 exponents
714682 // are supported in floating-point literals
715- let f1: f64 = from_str_hex ( "1p-123" ) . unwrap ( ) ;
716- 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 ( ) ;
717685 assert_eq ! ( FloatMath :: ldexp( 1f64 , -123 ) , f1) ;
718686 assert_eq ! ( FloatMath :: ldexp( 1f64 , -111 ) , f2) ;
719687
@@ -732,8 +700,8 @@ mod tests {
732700 fn test_frexp ( ) {
733701 // We have to use from_str until base-2 exponents
734702 // are supported in floating-point literals
735- let f1: f64 = from_str_hex ( "1p-123" ) . unwrap ( ) ;
736- 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 ( ) ;
737705 let ( x1, exp1) = f1. frexp ( ) ;
738706 let ( x2, exp2) = f2. frexp ( ) ;
739707 assert_eq ! ( ( x1, exp1) , ( 0.5f64 , -122 ) ) ;
0 commit comments