5.7. Working with Very Large Integers
In the event it becomes necessary, Ruby programmers can work with integers of arbitrary size. The transition from a Fixnum to a Bignum is handled automatically and transparently. In this following piece of code, notice how a result that is large enough is promoted from Fixnum to Bignum:
num1 = 1000000 # One million (10**6) num2 = num1*num1 # One trillion (10**12) puts num1 # 1000000 puts num1.class # Fixnum puts num2 # 1000000000000 puts num2.class # Bignum
The size of a Fixnum varies from one architecture to another. Calculations with Bignums are limited only by memory and processor speed. They take more memory and are obviously somewhat slower, but number-crunching with very large integers (hundreds of digits) is still reasonably practical.