Different exponent behavior for different ruby ​​versions

I am trying to compute 2^1000

in ruby ​​but I have different results for different versions. Any idea why?

Using 1.8.7:

~ » rbenv global system                                                                         ~  
~ » ruby --version                                                                              ~  
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
~ » irb                                                                                         ~  
>> 2 ** 1000
0
>> exit

      

Using ruby ​​1.9.3

~ » rbenv global 1.9.3-p194                                                                     ~  
~ » ruby --version                                                                              ~  
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.1.0]
~ » irb                                                                                         ~  
>> 2 ** 1000
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
>> exit

      

I can work around this syntax and get it to work, but I'm just wondering why this results in 0 in 1.8.7.

+3


source to share


1 answer


I'm sure you are experiencing the error mentioned in this post .



It looks like it was committed by this commit on the Ruby trunk , making it for Ruby 1.9.3-p0 and up.

0


source







All Articles