Search code examples
javaruby-on-railsrubyjrubybignum

Why does JRuby not recognize BigNums while Ruby does?


If I type this big integer:

puts 9997836544.class.to_s

and compile with ruby 1.86, it reports expectedly:

BigNum

while JRuby (1.1.4 in Netbeans) reports surprisingly:

Fixnum

I thought Java had a BigInteger class to correspond to the BigNum class in Ruby. If so, I would have expected JRuby and ruby to produce the same output.


Solution

  • Found this JRuby bug report:

    It seems that JRuby and MRI have different limits to separate Fixnum and Bignum.
    ...
    So, MRI uses 0x3fffffff as the biggest FixNum under 32bit environment.
    And JRuby always uses 64bit value: jruby -e 'p (0x7fffffffffffffff + 1).class' ---> Bignum.

    So try a bigger number and you should get a BigNum as you expect.