[Ironruby-core] Is the Fixnum size difference a problem?

Peter Bacon Darwin bacondarwin at googlemail.com
Fri Dec 21 15:53:09 EST 2007

The size of Fixnum in a standard C implementation of Ruby is a machine word
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 value
that you can hold in their Fixnum is 0x3fffffff.


IronRuby uses System.Int32 to hold its Fixnum values and doesn't have a flag
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 and
Bignum is supposedly transparent; you don't really care (although you may
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 for
CRuby is not a Bignum for IronRuby.


In CRuby:

0x40000000.div(0.0) => Infinity

In IronRuby:

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 under
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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071221/e9520750/attachment.html 

More information about the Ironruby-core mailing list