diff options
| author | bors <bors@rust-lang.org> | 2014-11-07 02:11:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-11-07 02:11:27 +0000 |
| commit | b03a2755193cd756583bcf5831cf4545d75ecb8a (patch) | |
| tree | f041f64af047756e5a473eb2130211f3f0a79be5 /src/libstd | |
| parent | 45cbdec4174778bf915f17561ef971c068a7fcbc (diff) | |
| parent | 18c328da27fedb563625718bdd5007e583455dec (diff) | |
| download | rust-b03a2755193cd756583bcf5831cf4545d75ecb8a.tar.gz rust-b03a2755193cd756583bcf5831cf4545d75ecb8a.zip | |
auto merge of #18713 : juxiliary/rust/master, r=alexcrichton
* `from_str_radix_float` gives incorrect results for negative float strings. Changes the accumulator used to start at -0.0 instead of -1.0. * Adds missing tests
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/num/strconv.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 612090a3a51..088ea89818e 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -451,7 +451,7 @@ pub fn from_str_radix_float<T: Float>(src: &str, radix: uint) -> Option<T> { }; // The significand to accumulate - let mut sig = if is_positive { _0 } else { -_1 }; + let mut sig = if is_positive { _0 } else { -_0 }; // Necessary to detect overflow let mut prev_sig = sig; let mut cs = src.chars().enumerate(); @@ -647,6 +647,22 @@ mod test { let fe : Option<f32> = from_str_radix_float("1e40", 10); assert_eq!(fe, Some(Float::infinity())) } + + #[test] + fn test_from_str_radix_float() { + let x1 : Option<f64> = from_str_radix_float("-123.456", 10); + assert_eq!(x1, Some(-123.456)); + let x2 : Option<f32> = from_str_radix_float("123.456", 10); + assert_eq!(x2, Some(123.456)); + let x3 : Option<f32> = from_str_radix_float("-0.0", 10); + assert_eq!(x3, Some(-0.0)); + let x4 : Option<f32> = from_str_radix_float("0.0", 10); + assert_eq!(x4, Some(0.0)); + let x4 : Option<f32> = from_str_radix_float("1.0", 10); + assert_eq!(x4, Some(1.0)); + let x5 : Option<f32> = from_str_radix_float("-1.0", 10); + assert_eq!(x5, Some(-1.0)); + } } #[cfg(test)] |
