From: Heesob Park Date: 2009-03-26T15:48:46+09:00 Subject: Re: Operator precedence of exponentiation (**) and complement (~) 2009/3/26 Andrew Savige : > > The operator precedence table at: > >  http://phrogz.net/ProgrammingRuby/language.html#table_18.4 > > states that the exponentiation operator (**) has higher precedence than > the complement operator (~). Ditto for operator precedence in Python. > > Yet the following program: > >  x = ~2**3 >  print x, "\n"      # prints -27 in Ruby; prints -9 in Python > > surprised me by printing -27 (I am using ruby 1.8.6). > > BTW, the following program prints -9 in both Ruby and Python: > >  x = ~(2**3) >  print x, "\n" > > Is this a Ruby bug? > According to the japanese reference manual(http://doc.loveruby.net/refm/api/view/spec/operator), this is not a bug. I guess this precedence change was made on ruby 1.8.0 C:\work\ruby168\bin>ruby -v -e 'p ~2**3' ruby 1.6.8 (2002-12-24) [i586-mswin32] -9 C:\work\ruby180\bin>ruby -v -e 'p ~2**3' ruby 1.8.0 (2003-08-04) [i386-mswin32] -27 Regards, Park Heesob