In 1.9, '-r mathn' results in NoMethodError for Bignum#**.
----------------------------------------------------------

                 Key: JRUBY-4247
                 URL: http://jira.codehaus.org/browse/JRUBY-4247
             Project: JRuby
          Issue Type: Bug
          Components: Extensions, Ruby 1.9
    Affects Versions: JRuby 1.4, JRuby 1.5
            Reporter: Hiro Asari


{noformat}
surfboard:jruby[git:personal]$ jruby --1.9 -r mathn -ve 
'n=0x8000_0000_0000_0000+47; p n**4'
jruby 1.5.0.dev (ruby 1.9.2dev trunk 24787) (2009-11-17 ad8b73a) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java]
/Users/asari/personal/jruby/lib/ruby/1.9/mathn.rb:50:in `**': undefined method 
`power!' for 9223372036854775855:Bignum (NoMethodError)
        from -e:1
surfboard:jruby[git:personal]$ jruby --1.9 -ve 'n=0x8000_0000_0000_0000+47; p 
n**4'
jruby 1.5.0.dev (ruby 1.9.2dev trunk 24787) (2009-11-17 ad8b73a) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java]
7237005577332262361485077344629993318496048279512298547155833600056910050625
{noformat}

In 1.9, 'mathn' aliases the default ** to {{power!}} and redefines ** for 
{{Fixnum}} and {{Bignum}}, i.e.,
{noformat}
class Fixnum
  remove_method :/
  alias / quo

  alias power! ** unless defined?(0.power!)

  def ** (other)
    if self < 0 && other.round != other
      Complex(self, 0.0) ** other
    else
      power!(other)
    end
  end

end

class Bignum
  remove_method :/
  alias / quo

  alias power! ** unless defined?(0.power!)

  def ** (other)
    if self < 0 && other.round != other
      Complex(self, 0.0) ** other
    else
      power!(other)
    end
  end

end
{noformat}

You see that these two classes are extended identically.

However, {{Bignum#power!}} is not defined at all, while {{Fixnum#power!}} is.

{noformat}
surfboard:sandbox$ jruby --1.9 -S irb
irb(main):001:0> a=5; b=2**63+47; nil
=> nil
irb(main):002:0> a.class
=> Fixnum
irb(main):003:0> b.class
=> Bignum
irb(main):004:0> a1=a.methods; b1=b.methods; nil
=> nil
irb(main):005:0> require 'mathn'
=> true
irb(main):006:0> a2=a.methods; b2=b.methods; nil
=> nil
irb(main):007:0> (a2-a1).sort
=> [:power!, :prime?, :prime_division]
irb(main):008:0> (b2-b1).sort
=> [:prime?, :prime_division]
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to