Skip to content

^ should have higher precedence than +-/* #45

Description

@codeman38

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.

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