如果我输入这个大整数:
puts 9997836544.class.to_s
并使用ruby 1.86进行编译,它预期会报告:
BigNum
而JRuby(Netbeans中为1.1.4)令人惊讶地报告:
Fixnum
我以为Java有一个BigInteger类对应于Ruby中的BigNum类.如果是这样,我会期望JRuby和ruby产生相同的输出.
最佳答案
找到了这个JRuby bug report:
原文链接:https://www.f2er.com/java/533005.htmlIt 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.
因此,尝试更大的数字,您将获得预期的BigNum.