Skip to content

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

@roniemartinez

Description

@roniemartinez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions