www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24648] New: Power operator should be unordered with unary

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 puremagic.com
          Reporter: qs.il.paperinik 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.

--
Jul 04