From: Dominik Bathon Date: 2005-07-02T10:27:59+09:00 Subject: Re: How and where Fixnum are created On Sat, 02 Jul 2005 02:32:38 +0200, Daniel Brockman wrote: > Okay, I realize that this explanation turned out pretty confusing. > For more information, you might search for ``ruby immediate values.'' > > I hope this helps at least a bit, If you look at ruby.h, you will find the following defines: #define FIXNUM_MAX (LONG_MAX>>1) #define FIXNUM_MIN RSHIFT((long)LONG_MIN,1) #define FIXNUM_FLAG 0x01 #define INT2FIX(i) ((VALUE)(((long)(i))<<1 | FIXNUM_FLAG)) #define LONG2FIX(i) INT2FIX(i) ... #define FIX2LONG(x) RSHIFT((long)x,1) #define FIX2ULONG(x) (((unsigned long)(x))>>1) #define FIXNUM_P(f) (((long)(f))&FIXNUM_FLAG) #define POSFIXABLE(f) ((f) <= FIXNUM_MAX) #define NEGFIXABLE(f) ((f) >= FIXNUM_MIN) #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f)) They should be self-explanatory after Daniel's nice explanation, and should clear it up further. You can also see how it works if you look at the object_id of Fixnums: >> 1.object_id => 3 >> 42.object_id => 85 >> ObjectSpace._id2ref(87) => 43 >> ObjectSpace._id2ref(-87) => -44 >> ObjectSpace._id2ref(-86) RangeError: 0xffffffaa is not id value from (irb):5:in `_id2ref' from (irb):5 Dominik