mathparse incorrectly treats exponentiation as lower precedence than multiplication, division, addition or subtraction in the to_postfix method, when it should be higher precedence:
>>> mathparse.parse('2 ^ 3 + 4 * 5')
8388608
>>> 2 ** 3 + 4 * 5
28
>>> 2 ** (3 + 4 * 5)
8388608
>>> mathparse.parse('2 + 3 * 4 ^ 5')
537824
>>> 2 + 3 * 4 ** 5
3074
>>> (2 + 3 * 4) ** 5
537824
The unit test for this (2 + 3 * (4 - 2) ^ 2 / 2) only happens to pass by accident, because 2+3*((4-2)^2)/2 and (2+3*(4-2))^(2/2) both coincidentally equal 8.
mathparse incorrectly treats exponentiation as lower precedence than multiplication, division, addition or subtraction in the
to_postfixmethod, when it should be higher precedence:The unit test for this (
2 + 3 * (4 - 2) ^ 2 / 2) only happens to pass by accident, because2+3*((4-2)^2)/2and(2+3*(4-2))^(2/2)both coincidentally equal 8.