class Bignum < Integer

Bignum objects hold integers outside the range of Fixnum. Bignum objects are created automatically when integer calculations would otherwise overflow a Fixnum. When a calculation involving Bignum objects returns a result that will fit in a Fixnum, the result is automatically converted.

For the purposes of the bitwise operations and [], a Bignum is treated as if it were an infinite-length bitstring with 2's complement representation.

While Fixnum values are immediate, Bignum objects are not—assignment and parameter passing work with references to objects, not the objects themselves.

instance methods

Arithmetic operations
Performs various arithmetic operations on big.
big + aNumeric Addition
big - aNumeric Subtraction
big * aNumeric Multiplication
big / aNumeric Division
big % aNumeric Modulo
big ** aNumeric Exponentiation
Bit operations
Performs various operations on the binary representations of the Bignum.
~ big Invert bits
big | aNumeric Bitwise OR
big & aNumeric Bitwise AND
big ^ aNumeric Bitwise EXCLUSIVE OR
big << aNumeric Left-shift aNumeric bits
big >> aNumeric Right-shift aNumeric bits (with sign extension)
big <=> aNumeric → -1, 0, +1
Comparison—Returns -1, 0, or +1 depending on whether big is less than, equal to, or greater than aNumeric. This is the basis for the tests in Comparable.
[ ]
big[ n ] → 0, 1
Bit Reference—Returns the nth bit in the (assumed) binary representation of big, where big[0] is the least significant bit.
a = 9**15 50.downto(0) do |n| print a[n] end


big.size → anInteger
Returns the number of bytes in the machine representation of big.
(256**10 - 1).size 12 (256**20 - 1).size 20 (256**40 - 1).size 40
big.to_f → aFloat
Converts big to a Float. If big doesn't fit in a Float, the result is infinity.
big.to_i → big
Returns big.
big.to_s → aString
Returns a string containing the decimal representation of big.
Show this content in its own window