Bug 24648 – Power operator should be unordered with unary prefix, not stronger

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-07-04T11:08:33Z
Last change time
2024-12-13T19:36:15Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#20481 →

Comments

Comment #0 by qs.il.paperinik — 2024-07-04T11:08:33Z
In mathematics texts, exponentiation binds stronger than unary prefix, that is, −2² = −(2²) = −4. I guess for this reason, in D, where exponentiation is a binary operator: `^^`, it also binds stronger than unary prefix operators. It’s the only exception to this rule: Unary operators bind stronger than binary ones. (Another is the template instantiation operator, for which the exception makes sense.) I suggest we make `^^` unordered with respect to unary prefix operators, that is, make `-x^^2` a parse error and the error message should tell the programmer that clarifying parentheses are needed: `(-x)^^2` or `-(x^^2)`. This is a similar situation as with comparison operators and bit-wise operators.
Comment #1 by dkorpel — 2024-07-04T21:28:27Z
> It’s the only exception to this rule: Unary operators bind stronger than binary ones. (Another is the template instantiation operator, for which the exception makes sense.) Implied here is that the exception for `^^` makes no sense, but you just showed how it's consistent with mathematical convention, so it makes total sense to me. Adding an error seems like needless code breakage and uglifying.
Comment #2 by robert.schadek — 2024-12-13T19:36:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20481 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB