mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
Merge pull request #181 from blueloveTH/support-an-alt-float-literal-form
Support an alternative float literal form
This commit is contained in:
commit
34f3ac32e7
@ -273,24 +273,25 @@ static bool is_unicode_Lo_char(uint32_t c) {
|
|||||||
const char* i = token_start;
|
const char* i = token_start;
|
||||||
while(kValidChars.count(*i)) i++;
|
while(kValidChars.count(*i)) i++;
|
||||||
std::string_view text(token_start, i - token_start);
|
std::string_view text(token_start, i - token_start);
|
||||||
curr_char = i;
|
this->curr_char = i;
|
||||||
|
|
||||||
if(i[-1] == 'L'){
|
if(text[0] != '.'){
|
||||||
add_token(TK("@long"));
|
// try long
|
||||||
return;
|
if(i[-1] == 'L'){
|
||||||
|
add_token(TK("@long"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// try integer
|
||||||
|
i64 int_out;
|
||||||
|
if(parse_int(text, &int_out, -1)){
|
||||||
|
add_token(TK("@num"), int_out);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try integer
|
|
||||||
i64 int_out;
|
|
||||||
bool ok = parse_int(text, &int_out, -1);
|
|
||||||
if(ok){
|
|
||||||
add_token(TK("@num"), int_out);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// try float
|
// try float
|
||||||
double float_out;
|
double float_out;
|
||||||
char* p_end;
|
char* p_end;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
float_out = std::strtod(text.data(), &p_end);
|
float_out = std::strtod(text.data(), &p_end);
|
||||||
}catch(...){
|
}catch(...){
|
||||||
@ -346,7 +347,12 @@ static bool is_unicode_Lo_char(uint32_t c) {
|
|||||||
add_token(TK(".."));
|
add_token(TK(".."));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add_token(TK("."));
|
char next_char = peekchar();
|
||||||
|
if(next_char >= '0' && next_char <= '9'){
|
||||||
|
eat_number();
|
||||||
|
}else{
|
||||||
|
add_token(TK("."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -59,3 +59,11 @@ assert math.isnan(0/0)
|
|||||||
assert 2**-600 == 0.0
|
assert 2**-600 == 0.0
|
||||||
assert 2.0 ** 600 == inf
|
assert 2.0 ** 600 == inf
|
||||||
assert (-2.0) ** 601 == -inf
|
assert (-2.0) ** 601 == -inf
|
||||||
|
|
||||||
|
# test .123 forms
|
||||||
|
assert float(".123") == 0.123
|
||||||
|
assert .123 == 0.123
|
||||||
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user