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

Replacing ^ as safe_power does not consider the proper order of operation #163

Open
roniemartinez opened this issue Jan 8, 2025 · 0 comments

Comments

@roniemartinez
Copy link

roniemartinez commented Jan 8, 2025

We used to use cexprtk which treats ^ as power operation. As we converted to simpleeval which treats this as bitwise XOR, we had to put the change advised in the README.

>>> import ast
>>> from simpleeval import safe_power

>>> s = SimpleEval()
>>> s.operators[ast.BitXor] = safe_power

>>> s.eval("3 ^ 2")
9

Unfortunately this does not change the order of operation. Below is an example (both should result into 6):

>>> s.eval("5**1+1")
6
>>> s.eval("5^1+1")
25
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

No branches or pull requests

1 participant