[MacRuby-devel] 32 bit Number Bug

Louis-Philippe default at spiralix.org
Mon Jun 14 10:28:51 PDT 2010


Hi folks,

there seems to be a bug in the 32bit release of 0.6 with numbers

arch -arch i386 macirb --simple-prompt
>> 0x44485250
            # reality check
=> 1145590352
>> NSNumber.numberWithInt(0x44485250)                              # then
see all 32 NSNumber are weird...
=> 71848528
>> NSNumber.numberWithFloat(0x44485250)
=> 1145590272.0
>> NSNumber.numberWithInt(1145590352)
=> 71848528
>> NSNumber.numberWithFloat(1145590352)
=> 1145590272.0

versus:

arch -arch x86_64 macirb --simple-prompt
>> 0x44485250
          # reality check
=> 1145590352
>> NSNumber.numberWithInt(0x44485250)
=> 1145590352
>> NSNumber.numberWithFloat(0x44485250)
=> 1145590400.0
>> NSNumber.numberWithInt(1145590352)
=> 1145590352
>> NSNumber.numberWithFloat(1145590352.0)                      # this is
weird again...
=> 1145590400.0

to look a bit further, the bug turning point seems to be here for the 32bit
release:

>> NSNumber.numberWithInt(536870910)
=> 536870910
>> NSNumber.numberWithInt(536870911)
=> 536870911
>> NSNumber.numberWithInt(536870912)
=> -536870912
>> NSNumber.numberWithInt(536870913)
=> -536870911

and here in the 64 bit:

>> NSNumber.numberWithInt(2147483646)
=> 2147483646
>> NSNumber.numberWithInt(2147483647)
=> 2147483647
>> NSNumber.numberWithInt(2147483648)
=> -2147483648
>> NSNumber.numberWithInt(2147483649)
=> -2147483647


also an other detail:

32bit turning point:
>> 536870911 / 16
=> 33554431

64bit turning point:
>> 2147483647 / 64
=> 33554431

Is there a workaround for these conversion problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100614/9144688b/attachment.html>


More information about the MacRuby-devel mailing list