[ https://issues.apache.org/jira/browse/GROOVY-7428?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King resolved GROOVY-7428. ------------------------------- Resolution: Won't Fix After further discussion, the "inconsistency" between the power and other operators was indeed by design, so the proposed change has been reverted. Basically, the design follows the principle that -x ** 2 when written as a mathematical formula (i.e. with the 2 as a superscript term immediately after x) the power is done before the negate. The majority of (but not all) mathematical journals follow this convention as do other programming languages which provide a specific power operator and have taken care to prioritize the operators as per these mathematical conventions. Languages such as Lua, Ruby and Python fall into this category. Many programming languages don't have a special power operator. Others like Scala have too rigid a priority on it's operators to support the mathematical convention. Microsoft Excel, does have a special power operator but decided not to adopt this convention to favor consistency between the operators ahead of following the mathematical conventions. With this input, we decided to keep the existing behavior and update the comments in the grammar file to reflect this priority. Now that we understand the history a bit more, it appears that the comments were never changed when the current operator priorities were baked into the grammar file before the 1.0 release and this discrepancy between the comments and the grammar was causing most of the confusion. > Change precedence priority of ** compared to pre/post inc/dec and unary > plus/minus > ---------------------------------------------------------------------------------- > > Key: GROOVY-7428 > URL: https://issues.apache.org/jira/browse/GROOVY-7428 > Project: Groovy > Issue Type: Improvement > Reporter: Paul King > Assignee: Paul King > Labels: breaking > Fix For: 2.5.0-beta-1 > > > Currently the precedence order is: > {noformat} > level 1: post inc/dec > level 2: power > level 3: pre inc/dec > {noformat} > The original intention, I believe, was always: > {noformat} > level 1: post inc/dec > level 2: pre inc/dec > level 3: power > {noformat} > This leads to some unintuitive behavior: > while these are the same: > {code} > println (-9 + 2) // -7 > println ((-9) + 2) // -7 > {code} > these are different: > {code} > println (-9 ** 2) // -81 actually: println (-(9 ** 2)) > println ((-9) ** 2) // 81 > {code} > Similar anomalies occur between {{**}} and {{++}}/{{--}} -- This message was sent by Atlassian JIRA (v6.3.4#6332)