blueloveTH 2024-03-04 17:27:13 +08:00
parent 6cf2f950cd
commit 1caa9e71c3
2 changed files with 26 additions and 1 deletions

View File

@ -273,10 +273,18 @@ static bool is_unicode_Lo_char(uint32_t c) {
void Lexer::eat_number() {
const char* i = token_start;
while(kValidChars.count(*i)) i++;
bool is_scientific_notation = false;
if(*(i-1) == 'e' && (*i == '+' || *i == '-')){
i++;
while(isdigit(*i) || *i=='j') i++;
is_scientific_notation = true;
}
std::string_view text(token_start, i - token_start);
this->curr_char = i;
if(text[0] != '.'){
if(text[0] != '.' && !is_scientific_notation){
// try long
if(i[-1] == 'L'){
add_token(TK("@long"));

View File

@ -67,3 +67,20 @@ assert eq(.5 *2, 1.0)
assert eq(2 * .5, 1.0)
assert eq(2 * (.5), 1.0)
assert eq(2 * (.5 + 1), 3.0)
assert 1e3 == 1000.0
assert 1e-3 == 0.001
assert -1e3 == -1000.0
assert -1e-3 == -0.001
assert 1e0 == 1.0
assert 1e-0 == 1.0
assert 2e3 == 2000.0
assert 2e3j == 2000j
assert -2e-3 == -0.002
assert -2e-3j == -0.002j
assert 3.4e-3 == 0.0034
assert 3.4e+3 == 3400.0