Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 05, 2015 [Issue 15288] The precedence of the exponentiation operator ^^ is too high. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15288 thomas.bockman@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|The exponentiation operator |The precedence of the |^^ doesn't follow the |exponentiation operator ^^ |standard type promotion |is too high. |rules. | --- Comment #1 from thomas.bockman@gmail.com --- So, I just realized what's actually going on here: the exponentiation operator *is* using the correct promotion rules, but, bizarrely, has higher precedence than the cast operator: I expect this: cast(N)1 ^^ cast(M)1 To be evaluated like this: (cast(N)1) ^^ (cast(M)1) But it is instead evaluated like this: cast(N)(1 ^^ cast(M)1) I'm not sure if anyone else actually uses this operator with integers, but if so I'd bet there are some bugs in the wild because of this. Looking at the operator precedence table on the dlang wiki: http://wiki.dlang.org/Operator_precedence I would say that groups 12 and 13 should be swapped. Otherwise you get truly weird stuff like: int[2] xs = [ 1, 2 ]; int* y = &(xs[0]); int z = *++y ^^ 7; // ERROR: incompatible types for ((y) ^^ (7)): 'int*' and 'int' Because this: *++y ^^ 7 Is interpreted as this: *++(y ^^ 7) Rather than what I would expect: (*++y) ^^ 7 Not only is this unexpected, it is also silly: * Exponentiation is not even defined for pointer types * The result of exponentiation cannot be incremented: it is an rvalue. * The dereference operator is not defined for integer types -- |
December 10, 2015 [Issue 15288] The precedence of the exponentiation operator ^^ is too high. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15288 Shriramana Sharma <samjnaa@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |samjnaa@gmail.com -- |
September 08, 2021 [Issue 15288] The precedence of the exponentiation operator ^^ is too high. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15288 Dennis <dkorpel@live.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dkorpel@live.nl Hardware|x86_64 |All OS|Linux |All Severity|normal |enhancement --- Comment #2 from Dennis <dkorpel@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. -- |
December 17, 2022 [Issue 15288] The precedence of the exponentiation operator ^^ is too high. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15288 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 |P4 -- |
June 28 [Issue 15288] The precedence of the exponentiation operator ^^ is too high. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15288 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |razvan.nitu1305@gmail.com Resolution|--- |WONTFIX --- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> --- Yes, we are far too late in the game to be doing such precedence changes now. -- |
Copyright © 1999-2021 by the D Language Foundation