1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

scanner: exponent without sign

This commit is contained in:
penguindark 2020-02-17 02:35:01 +01:00 committed by GitHub
parent 1007dd8f23
commit 80861f2219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -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++
}

View File

@ -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++
}

View File

@ -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
}