Class

Bignum

Extends:

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.

Public Methods
| Performs bitwise or between big and numeric.
% Returns big modulo other. See Numeric.divmod for more information.
& Performs bitwise and between big and numeric.
* Multiplies big and other, returning the result.
** Raises big to the exponent power (which may be an integer, float, or anything that will coerce to a number). The result may be a Fixnum, Bignum, or Float
+ Adds big and other, returning the result.
- Subtracts other from big, returning the result.
-@ Unary minus (returns a new Bignum whose value is 0-big)
/ Divides big by other, returning the result.
<< Shifts big left numeric positions (right if numeric is negative).
<=> Comparison—Returns -1, 0, or +1 depending on whether big is less than, equal to, or greater than numeric. This is the basis for the tests in Comparable.
== Returns true only if obj has the same value as big. Contrast this with Bignum#eql?, which requires obj to be a Bignum.
>> Shifts big right numeric positions (left if numeric is negative).
[] Bit Reference—Returns the nth bit in the (assumed) binary representation of big, where big[0] is the least significant bit.
^ Performs bitwise +exclusive or+ between big and numeric.
abs Returns the absolute value of big.
coerce MISSING: documentation
div Divides big by other, returning the result.
divmod See Numeric#divmod.
eql? Returns true only if obj is a Bignum with the same value as big. Contrast this with Bignum#==, which performs type conversions.
hash Compute a hash based on the value of big.
modulo Returns big modulo other. See Numeric.divmod for more information.
quo Returns the floating point result of dividing big by numeric.
remainder Returns the remainder after dividing big by numeric.
size Returns the number of bytes in the machine representation of big.
to_f Converts big to a Float. If big doesn’t fit in a Float, the result is infinity.
to_s Returns a string containing the representation of big radix base (2 through 36).
~ Inverts the bits in big. As Bignums are conceptually infinite length, the result acts as if it had an infinite number of one bits to the left. In hex representations, this is displayed as two periods to the left of the digits.
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.