Change to precedence of unary percentage operator in v14 is confusing #3349
kiprobinsonknack
started this conversation in
Design decisions
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In v14, the precedence or the
%
ormod
operator 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 = 200
100 / 50% = (100 / 50)% = 2% = 0.02
The 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
=5
10 / 200 % % 3
=((10 / 200)%) % 3
=((0.05)%) % 3
=0.0005 % 3
=0.0005
10 / 200 % % 3
=(10 / (200%)) % 3
=(10 / 2) % 3
=5 % 3
=2
Beta Was this translation helpful? Give feedback.
All reactions