java-为什么JRuby不能识别BigNums而Ruby却不能识别BigNums?
作者:互联网
如果我输入这个大整数:
puts 9997836544.class.to_s
并使用ruby 1.86进行编译,它预期会报告:
BigNum
而JRuby(Netbeans中为1.1.4)令人惊讶地报告:
Fixnum
我以为Java有一个BigInteger类对应于Ruby中的BigNum类.如果是这样,我会期望JRuby和ruby产生相同的输出.
解决方法:
找到了这个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.
因此,尝试更大的数字,您将获得预期的BigNum.
标签:bignum,jruby,ruby,ruby-on-rails,java 来源: https://codeday.me/bug/20191210/2103579.html