noreply / rubyforge.org wrote:
> Summary: the sign of a number is omitted when squaring it. -2**2 vs (-2)**2
> 
> Initial Comment:
> Due to the way ruby interprets formula's, squaring a negative number isn't possible unless you use brackets. This caught me unaware, and might be counterintuitive for more people.
> 
> irb(main):018:0> -2**2
> => -4
> irb(main):019:0> (-2)**2
> => 4
> 
> 
> Some trouble:
> irb(main):006:0> 3-2**2
> => -1
> The above works fine right now, but only because it is seen as 3 - 2**2. If "-2" is recognized as a negative number, and "- 2" as 'substract 2, then the 3-2**2 example should rise an error.

FWIW, I don't see how this is a bug or even bad behavior. Other 
languages work similiarly:

    $ perl -le 'print -2**2'
    -4
    $ perl -le 'print 3-2**2'
    -1

This seems like one of those "could see it either way" issues. I 
personally think the Ruby behavior is consistent. Changing it could 
break existing code. Using parens to disambiguate the expression works fine.

-Nate