Bug #14378
On windows, RUBY_FIXNUM_MAX of 64 bits ruby is 32 bits
Description
On windows, start an IRB of a 64-bits ruby, enter these code:
(1<<29).equal?(1<<29)
#=>true
(1<<30).equal?(1<<30)
#=>false
So, it is that FIXNUM of the 64-bits ruby is a 32-bits data?
But my friend try these code on linux platform and all got true(it means FIXNUM is 64bits)
Then I opened ruby/ruby.h and found this:
#define RUBY_FIXNUM_MAX (LONG_MAX>>1)
The LONG_MAX of my compiler(msvc140, vs2017) is 2147483647, and the ruby which is installed by ruby-installer also have the same problem.
Updated by nobu (Nobuyoshi Nakada) about 3 years ago
- Description updated (diff)
HfCloud (Xiangyu Shi) wrote:
So, it is that FIXNUM of the 64-bits ruby is a 32-bits data?
Yes, we are using long
for fixnums, and Windows is the so-called IL32LLP64 platform.
To "fix" this, or relax this limitation, we have to replace tons of long
in the source code.
Updated by HfCloud (Xiangyu Shi) about 3 years ago
I'm using vs2017 and embed ruby interpreter in my game engine. In certain situation I need to use Fixnum to pass values of pointers(64-bits pointers). So ruby will use big integer to pass the pointer's values, what may cause unsatisfying performance on runtime speed.
Updated by HfCloud (Xiangyu Shi) about 3 years ago
nobu (Nobuyoshi Nakada) wrote:
To "fix" this, or relax this limitation, we have to replace tons of
long
in the source code.
Oh...I tried just now. The codes uses so large amount of '#define' to alias types' names, it makes the work more difficult.....
what I only want to say is 'why didn't use typedef?...' I found that Matz once said 'IL32LLP64 platform is not hackneyed' :(
Updated by Eregon (Benoit Daloze) about 3 years ago
This is indeed very surprising that on a platform with 64-bit pointers, Fixnum are still only 30 bits.
+1 to making this more intuitive.
It creates a lot of weird edge cases in ruby/spec.
There are also places in the code where VALUE is used as a synonym of unsigned long (e.g.: rb_uint2inum(VALUE)) but those should just be replaced by "unsigned long".
Updated by spatulasnout (B Kelly) about 3 years ago
sxysxygm@gmail.com wrote:
what I only want to say is 'why didn't use typedef?...'
In the 1980s, when the 'int' type was fluctuating between 16 bits and
32 bits, we learned to NEVER trust naked C types.
This defensive tactic may have been lost during the 90's and early 2000's
while 32-bit platforms had a lengthy run.
(Interesting to see the old problem re-emerge finally, 30 years later.)
Regards,
Bill
Updated by spatulasnout (B Kelly) about 3 years ago
a mere data point:
(cygwin-64 ruby includes the full 64-bit Fixnum)
>> RUBY_VERSION => "2.2.5" >> `uname -om` => "x86_64 Cygwin\n" >> (1<<61).class => Fixnum >> (1<<62).class => Bignum