Skip to content

Commit 0652af2

Browse files
committed
Rollup merge of rust-lang#48235 - varkor:parse-float-lonely-exponent, r=alexcrichton
Make ".e0" not parse as 0.0 This forces floats to have either a digit before the separating point, or after. Thus `".e0"` is invalid like `"."`, when using `parse()`. Fixes rust-lang#40654. As mentioned in the issue, this is technically a breaking change... but clearly incorrect behaviour at present.
2 parents 268b6d6 + c0e87f1 commit 0652af2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: src/libcore/num/dec2flt/parse.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ pub fn parse_decimal(s: &str) -> ParseResult {
7373
}
7474
Some(&b'.') => {
7575
let (fractional, s) = eat_digits(&s[1..]);
76-
if integral.is_empty() && fractional.is_empty() && s.is_empty() {
76+
if integral.is_empty() && fractional.is_empty() {
77+
// We require at least a single digit before or after the point.
7778
return Invalid;
7879
}
7980

Diff for: src/libcore/tests/num/dec2flt/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ fn lonely_dot() {
101101
assert!(".".parse::<f64>().is_err());
102102
}
103103

104+
#[test]
105+
fn exponentiated_dot() {
106+
assert!(".e0".parse::<f32>().is_err());
107+
assert!(".e0".parse::<f64>().is_err());
108+
}
109+
104110
#[test]
105111
fn lonely_sign() {
106112
assert!("+".parse::<f32>().is_err());

0 commit comments

Comments
 (0)