[Issue 15288] The precedence of the exponentiation operator ^^ is too high.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 8 15:35:19 UTC 2021


Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
                 CC|                            |dkorpel at live.nl
           Hardware|x86_64                      |All
                 OS|Linux                       |All
           Severity|normal                      |enhancement

--- Comment #2 from Dennis <dkorpel at live.nl> ---
-2^2 in math evaluates to -(2^2) = -4, not (-2)^2 = 4. This is fairly
consistent in e.g. Wolfram Alpha, Google search's calculator, Python (`-2**2`
in that case) etc. So I think it's good that D also has -2^^2 = -4. It makes
less sense for the cast operator or pointer operators I agree, but do you
really want to add another precedence level for that? To me, that sounds like
it would only complicate things more. At least now you know the precedence of
every unary operator is the same.


More information about the Digitalmars-d-bugs mailing list