Skip to content

Unary minus precedence? #565

@dronir

Description

@dronir

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).

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions