@@ -451,7 +451,7 @@ pub fn from_str_radix_float<T: Float>(src: &str, radix: uint) -> Option<T> {
451
451
} ;
452
452
453
453
// The significand to accumulate
454
- let mut sig = if is_positive { _0 } else { -_1 } ;
454
+ let mut sig = if is_positive { _0 } else { -_0 } ;
455
455
// Necessary to detect overflow
456
456
let mut prev_sig = sig;
457
457
let mut cs = src. chars ( ) . enumerate ( ) ;
@@ -647,6 +647,22 @@ mod test {
647
647
let fe : Option < f32 > = from_str_radix_float ( "1e40" , 10 ) ;
648
648
assert_eq ! ( fe, Some ( Float :: infinity( ) ) )
649
649
}
650
+
651
+ #[ test]
652
+ fn test_from_str_radix_float ( ) {
653
+ let x1 : Option < f64 > = from_str_radix_float ( "-123.456" , 10 ) ;
654
+ assert_eq ! ( x1, Some ( -123.456 ) ) ;
655
+ let x2 : Option < f32 > = from_str_radix_float ( "123.456" , 10 ) ;
656
+ assert_eq ! ( x2, Some ( 123.456 ) ) ;
657
+ let x3 : Option < f32 > = from_str_radix_float ( "-0.0" , 10 ) ;
658
+ assert_eq ! ( x3, Some ( -0.0 ) ) ;
659
+ let x4 : Option < f32 > = from_str_radix_float ( "0.0" , 10 ) ;
660
+ assert_eq ! ( x4, Some ( 0.0 ) ) ;
661
+ let x4 : Option < f32 > = from_str_radix_float ( "1.0" , 10 ) ;
662
+ assert_eq ! ( x4, Some ( 1.0 ) ) ;
663
+ let x5 : Option < f32 > = from_str_radix_float ( "-1.0" , 10 ) ;
664
+ assert_eq ! ( x5, Some ( -1.0 ) ) ;
665
+ }
650
666
}
651
667
652
668
#[ cfg( test) ]
0 commit comments