The size of Fixnum in a standard C implementation of Ruby is a machine
minus one bit. I.E. For most 32 bit machines that is 31 bits. (The
implementation uses the bottom bit as a flag). Therefore the largest
that you can hold in their Fixnum is 0x3fffffff.
IronRuby uses System.Int32 to hold its Fixnum values and doesn’t have a
bit so the size of Fixnum in IronRuby is 32 bits. Therefore the largest
value you can hold is 0x7fffffff.
This shouldn’t run into any problems since the transition between Fixnum
Bignum is supposedly transparent; you don’t really care (although you
know) what class is representing the value you are working with.
Unfortunately, I recently noticed that the div method has different
semantics depending upon whether you are a Fixnum or Bignum.
some_fixnum.div(0.0) => raises FloatDomainError
some_bignum.div(0.0) => Infinity
IronRuby has the same semantics, except that of course what is a Bignum
CRuby is not a Bignum for IronRuby.
0x40000000.div(0.0) => Infinity
0x40000000.div(0.0) => raises FloatDomainError
Now clearly this is a problem with the fundamental implementation of
Fixnum/Bignum but Rubinius seems to follow suit and I assume JRuby too
(although I haven’t checked).
What are your thoughts on dealing with this issue? Should we brush it
the carpet and hope that Ruby 2.0 will fix it or what? Should we force
IronRuby’s Fixnum to be 31 bits?
Any ideas most welcome.