groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: precedence rules for power operator vs -, +, ++, --
Date Sun, 07 Jun 2015 10:40:47 GMT
Am 06.06.2015 13:08, schrieb Paul King:
[...]
> def x = 5
> assert -x ** 2 == -25  // treated as -(x ** 2)
> assert --x ** 2 == 24  // treated as --(x ** 2)
>
> This behavior is different to the other operators and different to what
> the comments in the grammar describe as the intended behavior but the
> order of two rules was presumably accidentally reversed in the grammar.
>
> After the change, the following executes:
>
> def x = 5
> assert -x ** 2 == 25   // treated as (-x) ** 2
> assert --x ** 2 == 16  // treated as (--x) ** 2

I just checked Ruby and Python and there -2**4 will return -16, same for 
-2^4 in Lua. So now I am wondering if that is the right thing for unary 
minus

bye blackdrag

-- 
Jochen "blackdrag" Theodorou
blog: http://blackdragsview.blogspot.com/


Mime
View raw message