diff --git a/vlib/compiler/scanner.v b/vlib/compiler/scanner.v index 855c1c1e3c..f1c2d23750 100644 --- a/vlib/compiler/scanner.v +++ b/vlib/compiler/scanner.v @@ -213,8 +213,13 @@ fn (s mut Scanner) ident_dec_number() string { } // scan exponential part mut has_exponential_part := false - if s.expect('e+', s.pos) || s.expect('e-', s.pos) { - exp_start_pos := s.pos += 2 + if s.expect('e', s.pos) || s.expect('E', s.pos) { + exp_start_pos := (s.pos++) + + if s.text[s.pos] in [`-`, `+`] { + s.pos++ + } + for s.pos < s.text.len && s.text[s.pos].is_digit() { s.pos++ } diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index dfca75dddc..331aac7efb 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -208,8 +208,13 @@ fn (s mut Scanner) ident_dec_number() string { } // scan exponential part mut has_exponential_part := false - if s.expect('e+', s.pos) || s.expect('e-', s.pos) { - exp_start_pos := s.pos += 2 + if s.expect('e', s.pos) || s.expect('E', s.pos) { + exp_start_pos := (s.pos++) + + if s.text[s.pos] in [`-`, `+`] { + s.pos++ + } + for s.pos < s.text.len && s.text[s.pos].is_digit() { s.pos++ } diff --git a/vlib/v/scanner/scanner_test.v b/vlib/v/scanner/scanner_test.v index 7c7553c563..6c3f3c0b28 100644 --- a/vlib/v/scanner/scanner_test.v +++ b/vlib/v/scanner/scanner_test.v @@ -33,7 +33,16 @@ fn test_scan() { assert c == 9 c = 1_000_000 assert c == 1000000 + + // test float conversion and reading d := f64(23_000_000e-3) assert int(d) == 23000 + mut e := f64(1.2E3) * f64(-1e-1) + assert e == -120.0 + e = f64(1.2E3) * f64(1e-1) + assert e == 120.0 + assert 1.23e+10 == 1.23e10 + assert 1.23e+10 == 1.23e0010 + assert -1.23e+10 == 1.23e0010*-1.0 }