Change to precedence of unary percentage operator in v14 is confusing #3349
Closed
kiprobinsonknack
started this conversation in
Design decisions
Replies: 2 comments 4 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks for your input @kiprobinsonknack. It would be neat to improve the behavior of the percentage operator if possible to align with the common expectations. Help would be very welcome. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment




Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In v14, the precedence or the
%ormodoperator was changed to be equal to multiplication and division. (see: #3303, #3301, #3311)However, this also affects the unary percentage operator which I think many users will find confusing.
100 / 50% = 100 / (50%) = 100 / 0.5 = 200100 / 50% = (100 / 50)% = 2% = 0.02The unary
%operator should have higher precedence than the binary%modulo operator. There are other cases of unary operators having higher precedence than the same symbol used as a binary operator (+and-work this way).I believe this would necessitate a major version change (e.g. v15), as this would be a breaking change.
Here is another example that combines the unary and binary percentage operators for evaluating
10 / 200 % % 3:10 / 200 % % 3=10 / ((200%) % 3)=10 / (2 % 3)=10 / 2=510 / 200 % % 3=((10 / 200)%) % 3=((0.05)%) % 3=0.0005 % 3=0.000510 / 200 % % 3=(10 / (200%)) % 3=(10 / 2) % 3=5 % 3=2Beta Was this translation helpful? Give feedback.
All reactions