Bugs: Browse | Submit New | Admin

[#23446] Adding/subtracting a Bignum to a Fixnum returns a Float

Date:
2009-01-05 15:10
Priority:
3
Submitted By:
Daniele Alessandri (nrk)
Assigned To:
Jim Deville (jredville)
Category:
None
State:
Open
Summary:
Adding/subtracting a Bignum to a Fixnum returns a Float

Detailed description
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

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-02-28 01:20
Sender: Tomas Matousek

Fixed.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_totmat2009-02-28 01:20tmat
assigned_tonone2009-01-07 01:23tmat