[Issue 24648] New: Power operator should be unordered with unary prefix, not stronger
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 4 11:08:33 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24648
Issue ID: 24648
Summary: Power operator should be unordered with unary prefix,
not stronger
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: qs.il.paperinik at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list