axiacore / py-expression-eval

MIT License
149 stars 54 forks source link

Swap math.pow with self.pow #69

Closed Sbozzolo closed 3 years ago

Sbozzolo commented 3 years ago

Before this commit, pow was the only binary function that doesn't use the corresponding operator but calls pow in math. This commit defines a pow function that invokes the corresponding operator (**).

Using ** is preferable because it is slightly faster and preservers integers (see, https://www.semicolonworld.com/question/56223/exponentials-in-python-x-y-vs-math-pow-x-y). Moreover, it improves type compatibility, since now the function works with user-defined classes (as long as they have a __pow__ method), math.pow only supports numbers.

Sbozzolo commented 3 years ago

@cansadadeserfeliz, any thought of this?

cansadadeserfeliz commented 3 years ago

✅ @Sbozzolo thanks!