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
Precedence of the modulus operator #3189
Comments
You can find the operator precedence here: https://mathjs.org/docs/expressions/syntax.html#precedence You can check how an expression is evaluated via: math.parse('250/10%10').toString({ parenthesis: 'all'})
// "250 / (10 % 10)" If you need an alterative order of exection, you can use parenthesis: math.evaluate('(250 / 10) % 10')
// 5 |
@josdejong I'm sorry for reviving this discussion, but according to the link provided before, division and modulus have the same precedence, which means the evaluation should be done from the left to the right. |
Thanks, you're right. I now see that the documentation is not up to date. The order of predencence of the modules operator was changed in #2304 I think, or maybe in consecutive changes around implementing special rules for implicit multiplication. I've updated the docs to be consistent with the actual behavior: 599f4ee Separately, we can discuss if we want to make changes in this behavior or not. |
Why does 250/10%10 return the result Infinity? Why calculate % first and then /
The text was updated successfully, but these errors were encountered: