Adding/subtracting a Bignum to a Fixnum always returns a Float instead of returning a Fixnum or a Bignum (the actual
value type depends on the size of the result). See below, tested on SVN r181:
IronRuby SVN r181:
>>> 1 + 1_000_000_000_000
=> 1000000000001.0
>>> 1 - 1_000_000_000_000
=> -999999999999.0
>>> 0 - -2_147_483_647
=> 2147483647
>>> 0 - -2_147_483_648
=> 2147483648.0
MRI 1.8.6:
irb(main):001:0> 1 + 1_000_000_000_000
=> 1000000000001
irb(main):002:0> 1 - 1_000_000_000_000
=> -999999999999
irb(main):003:0> 0 - -2_147_483_647
=> 2147483647
irb(main):004:0> 0 - -2_147_483_648
=> 2147483648
This bug is related to a missing overload for both the Add and Sub methods in IronRuby.Builtins.FixnumOps that takes
a BigInteger as the type for "other" and returns an object type (see the attachment for a proposed patch).
Without this overload, BigInteger instances are coerced to doubles and then passed to the respective overloads of Add
and Sub.
Here are the results obtained after patching IronRuby:
IronRuby SVN r181 (patched):
>>> 1 + 1_000_000_000_000
=> 1000000000001
>>> 1 - 1_000_000_000_000
=> -999999999999
>>> 0 - -2_147_483_647
=> 2147483647
>>> 0 - -2_147_483_648
=> 2147483648
|