[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Why is 0x7FFFFFFF Bignum and not Fixnum ?

seebs

4/30/2007 4:08:00 AM

In message <d1522f1fde212135fae0bea4fd1142d1@ruby-forum.com>, Mr Magpie writes:
>>> 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.

Because 0x40000000 is either the sign bit or the magic flag. I don't know
how Ruby does that part, but that's what I'd expect. There's no
"unsigned" types here.

-s

5 Answers

Mr Magpie

4/30/2007 4:26:00 AM

0

> Because 0x40000000 is either the sign bit or the magic flag.

0x80000000 would be the sign bit. What is this "magic flag" that seems
to be occupying 0x40000000 ?

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

Jano Svitok

4/30/2007 1:59:00 PM

0

On 4/30/07, Mr Magpie <gazmcgheesubs@yahoo.com.au> wrote:
> > Because 0x40000000 is either the sign bit or the magic flag.
>
> 0x80000000 would be the sign bit. What is this "magic flag" that seems
> to be occupying 0x40000000 ?

This is kind of "hack" / implementation detail:

this bit is a flag that distinguishes between immediate values and
full objects.
the number is either
- 31 bit signed fixnum
- nil
- true
- false
- symbol
- pointer/handle to VALUE object
For more details see
http://www.oreillynet.com/ruby/blog/2006/01/the_ruby_va...

Gary Wright

4/30/2007 4:42:00 PM

0


On Apr 30, 2007, at 9:58 AM, Jano Svitok wrote:
> This is kind of "hack" / implementation detail:
>
> this bit is a flag that distinguishes between immediate values and
> full objects.

This is another of my attempts to kill the 'immediate value' meme
in Ruby. Feel free to ignore.


I think Ruby's semantics are clearer if you consider that the only
'values' in the language are references. These values reference
objects but the objects themselves are not manipulated as values
by the language.

Some references indicate implicit objects (nil, false, true,
fixnums, and symbols) and some references indicate explicit objects
(everything else). This differentiation is mostly an
implementation detail.

This point of view makes assignment and parameter passing semantics
consistent regardless of what objects are being referenced.


Gary Wright




Jano Svitok

4/30/2007 4:52:00 PM

0

On 4/30/07, Gary Wright <gwtmp01@mac.com> wrote:
>
> On Apr 30, 2007, at 9:58 AM, Jano Svitok wrote:
> > This is kind of "hack" / implementation detail:
> >
> > this bit is a flag that distinguishes between immediate values and
> > full objects.
>
> This is another of my attempts to kill the 'immediate value' meme
> in Ruby. Feel free to ignore.
>
>
> I think Ruby's semantics are clearer if you consider that the only
> 'values' in the language are references. These values reference
> objects but the objects themselves are not manipulated as values
> by the language.
>
> Some references indicate implicit objects (nil, false, true,
> fixnums, and symbols) and some references indicate explicit objects
> (everything else). This differentiation is mostly an
> implementation detail.
>
> This point of view makes assignment and parameter passing semantics
> consistent regardless of what objects are being referenced.
>
>
> Gary Wright

Thanks, your explanation seems clearer.

Mr Magpie

5/1/2007 1:33:00 AM

0

Thanks for the informative answers. I see the reasoning now.

Has anyone done performance comparisons of Fixnum and Bignum ?

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