[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Why is 0x7FFFFFFF Bignum and not Fixnum ?

Mr Magpie

4/30/2007 4:04:00 AM

According to the Pickaxe book :
"A Fixnum holds Integer values that can be represented in a native
machine word (minus 1 bit). If any operation on a Fixnum exceeds this
range, the value is automatically converted to a Bignum."

In IRB :

>> 0x3FFFFFFF.class
=> Fixnum
>> 0x3FFFFFFF.size
=> 4
As expected, this comfortably fits into 32 bits, but so should this :

>> 0x7FFFFFFF.class
=> Bignum
>> 0x7FFFFFFF.size
=> 4

1) Why has it gone to Bignum ? it shouldn't do this until 0x80000000.
2) Interestingly, BigNum has recognised it fits into 32 bits, but it was
upsized anyway !

I'm trying to do some performance critical bit manipulations (without
leaving ruby) and this means I'll be using BigNum unnecessarily.

Regards

Magpie

--
Posted via http://www.ruby-....