mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
This commit is contained in:
parent
6cf2f950cd
commit
1caa9e71c3
@ -273,10 +273,18 @@ static bool is_unicode_Lo_char(uint32_t c) {
|
|||||||
void Lexer::eat_number() {
|
void Lexer::eat_number() {
|
||||||
const char* i = token_start;
|
const char* i = token_start;
|
||||||
while(kValidChars.count(*i)) i++;
|
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);
|
std::string_view text(token_start, i - token_start);
|
||||||
this->curr_char = i;
|
this->curr_char = i;
|
||||||
|
|
||||||
if(text[0] != '.'){
|
if(text[0] != '.' && !is_scientific_notation){
|
||||||
// try long
|
// try long
|
||||||
if(i[-1] == 'L'){
|
if(i[-1] == 'L'){
|
||||||
add_token(TK("@long"));
|
add_token(TK("@long"));
|
||||||
|
@ -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.0)
|
assert eq(2 * (.5), 1.0)
|
||||||
assert eq(2 * (.5 + 1), 3.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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user