-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Not sure if this is intentional or not, but it caused me some confusion. If it's intentional, I'd be interested to hear the rationale.
The precedence of the unary minus seems to be over exponentiation such that -(x-y)^2
equals (-(x-y))^2
, so for example -(1-3)^2 == 4
. This differs from at least Python, where -(x-y)**2
equals -((x-y)**2)
.
Might be a matter of taste (as Python is my major language), but for me this latter way is more intuitive, and makes for prettier expressions. I was writing something with a gaussian function exp(-(x-a)^2)
and got quite unexpected numbers out at first. Had to write it exp(-((x-a)^2))
which looks a bit cluttered.
I think this should at least be mentioned in the manual somewhere (at least I couldn't find much about operator precedence).