[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:31:00 AM

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

Remember how it said you get "32 bits, minus one"?

What that means is you have a total of 31 bits available for values.

So. The largest 31-bit number is 0x7FFF,FFFF. But wait! What about
negative numbers? How do we represent those? If we are using a 31-bit
representation, then the topmost of *those 31 bits* must be the sign
bit, so the highest number is 0x3FFF,FFFF -- because 0x7FFF,FFFF is
negative.

Unless something else similar is being done; I never read the source. I
just know that, if you have 31 bits available for positive and negative
numbers, you can't represent 0x7FFF,FFFF as a positive number in that
range, and Ruby seems to have no unsigned types.

-s

2 Answers

Mr Magpie

4/30/2007 5:16:00 AM

0

unknown wrote:
> In message <b6597fbb7656f667941d80d0f00bfd63@ruby-forum.com>, Mr Magpie
> writes:
>>> 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 ?
>
> Remember how it said you get "32 bits, minus one"?
>
> What that means is you have a total of 31 bits available for values.

Oh, right!

>
> So. The largest 31-bit number is 0x7FFF,FFFF. But wait! What about
> negative numbers? How do we represent those? If we are using a 31-bit
> representation, then the topmost of *those 31 bits* must be the sign
> bit, so the highest number is 0x3FFF,FFFF -- because 0x7FFF,FFFF is
> negative.
>
> Unless something else similar is being done; I never read the source. I
> just know that, if you have 31 bits available for positive and negative
> numbers, you can't represent 0x7FFF,FFFF as a positive number in that
> range, and Ruby seems to have no unsigned types.
>

Oh really, thats kinda sad - the abstractions are getting in the way...

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

Bill Kelly

4/30/2007 6:45:00 AM

0

From: "Mr Magpie" <gazmcgheesubs@yahoo.com.au>
>
>> So. The largest 31-bit number is 0x7FFF,FFFF. But wait! What about
>> negative numbers? How do we represent those? If we are using a 31-bit
>> representation, then the topmost of *those 31 bits* must be the sign
>> bit, so the highest number is 0x3FFF,FFFF -- because 0x7FFF,FFFF is
>> negative.
>>
>> Unless something else similar is being done; I never read the source. I
>> just know that, if you have 31 bits available for positive and negative
>> numbers, you can't represent 0x7FFF,FFFF as a positive number in that
>> range, and Ruby seems to have no unsigned types.
>>
>
> Oh really, thats kinda sad - the abstractions are getting in the way...

I think I've missed unsigned ints in ruby about as often as I've ever
missed unsigned floats. ;)

If you really need fast 32-bit unsigned int manipulation, possibly RubyInline
might be of use?

http://www.zenspider.com/ZSS/Products/R...


HTH,

Bill