Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponents with sign should be recognized as decimal numbers. #213

Closed
faze-geek opened this issue Feb 23, 2024 · 6 comments · Fixed by nesbox/TIC-80#2477
Closed

Exponents with sign should be recognized as decimal numbers. #213

faze-geek opened this issue Feb 23, 2024 · 6 comments · Fixed by nesbox/TIC-80#2477

Comments

@faze-geek
Copy link
Contributor

Python 3.9 -

>>> a = 1e2
>>> a
100.0
>>> a = 1e-2
>>> a
0.01

Pocketpy -

>>> a = 1e2
>>> a
100.0
>>> a = 1e-2
  File "<stdin>", line 1
    a = 1e-2
          ^
SyntaxError: invalid number literal
>>> a = 1e+2
  File "<stdin>", line 1
    a = 1e+2
          ^
SyntaxError: invalid number literal
@faze-geek
Copy link
Contributor Author

This is not really an error in code but an extension of the partial implementation of exponentiation that is already supported in pocketpy. Hence, I didn't open it up as a bug.

@gimmeursocks
Copy link

gimmeursocks commented Feb 24, 2024

@blueloveTH i dont know if i should make a pull request as i dont know if this behaviour is intended or not but i modified lexer::eat_number

if it passes by a -ve or a +ve character it skips it and parses the rest

       if(text[text.size()-1] == 'e'){
            if(*i == '+' || *i == '-'){
                i++;
                while(kValidChars.count(*i)) i++;
                text = std::string_view(token_start, i - token_start);
                this->curr_char = i;
            }
        }

        // try float
        double float_out;
        char* p_end;
        try{
            float_out = std::strtod(text.data(), &p_end);
        }catch(...){
            SyntaxError("invalid number literal");
        }

it passes all tests but as i said im reluctant to make a pr for this.

@blueloveTH
Copy link
Collaborator

I know about this. But I am reluctant to fix it.

@carlkl
Copy link

carlkl commented Feb 25, 2024

Could this be noted in https://pocketpy.dev/features/differences/, as this kind of literals are quite common?

@faze-geek
Copy link
Contributor Author

As mentioned in the documentation pocketpy is a project also being heavily used for scientific computing. In that context it is crucial to have special numbers/constants like (Inf, eps, e, pi etc.) and their various formats.
Hence I'm a bit confused on the reluctance to support this literal.

@carlkl
Copy link

carlkl commented Feb 26, 2024

Maybe a C++ runtime math parser like https://beltoforion.de/en/muparserx/ could be useful as an addition?
EDIT: muparsex needs STL unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants