-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 % (mod) is higher than * and / #3301
Comments
can i work on this issue. |
Yes, the mathjs documentation is clear on this behavior. It is just different than just about any other system. But I would not recommend working on changing it unless the designer @josdejong agrees there should be a change. He may have his reasons for the unusual behavior, which I would respect. So this issue was more of a proposal/query as to why the departure from norms. I think if the current behavior is retained, such a rationale should be added to the documentation. |
Thanks for bringing this up Glen. The precedence of the modulus operator regularly leads to questions and unexpected behavior. I think it would be a good thing to bring bring the behavior in line with other applications: let module have the same precedence as multiplication and division. Originally, modulus had the same precedence as multiplcation and division. I think the precedence was accidentally changed as as unintened side effect of implementing support for using It would be great if you can pick this up @nkumawat34 , though it's not the easiest first issue. Do you like a challenge? 😉 |
I will pick it. |
Thanks |
Please review my PR #3311 |
👍 I'll look into it this week, thanks!! |
The issues section is used only for bug reports. Please use the Discussions section to ask questions and share ideas and suggestions.
Describe the bug
Unlike in any other language I have checked, the precedence of
%
(ormod
) used as a binary remainder operator is higher than * and /. As it is essentially a division operation, its precedence should be the same as * and /, as it is in essentially every other language checked.To Reproduce
Evaluate
3.6 * 28 % 25
. Currently mathjs produces 10.8 = 3.6 * 3 = 3.6 * (28 % 25). It should produce 0.8 = 100.8 % 25 = (3.6 * 28) % 25, as multiplicative/division operators should be evaluated left to right.The text was updated successfully, but these errors were encountered: