← index

BigInteger

inherits Object

An arbitrary-precision integer. Construct explicitly with BigInteger.of: (a decimal String or an Integer); arithmetic never mixes silently -- a plain Integer operand is 'message not understood', so convert both sides first. Division truncates toward zero, like Integer.

(BigInteger.of:2).pow:100     "* -> 1267650600228229401496703205376

Class methods

of:String
of:Integer

A BigInteger from a decimal String (any magnitude; raises a ValueError for a non-integer string) or from an Integer.

BigInteger.of:'123456789012345678901234567890'     "* -> 123456789012345678901234567890
BigInteger.of:42                                    "* -> 42

native

Instance methods

%:BigInteger

The remainder after truncating division; takes the dividend's sign. Raises an ArithmeticError on a zero divisor.

(BigInteger.of:100) % (BigInteger.of:7)     "* -> 2

native

*:BigInteger

The product of two BigIntegers.

native

+:BigInteger

The sum of two BigIntegers, at any magnitude.

(BigInteger.of:10) + (BigInteger.of:32)     "* -> 42

native

-:BigInteger

The difference of two BigIntegers.

native

/:BigInteger

The quotient of two BigIntegers, truncated toward zero (matching Integer /); raises an ArithmeticError on a zero divisor.

(BigInteger.of:100) / (BigInteger.of:7)     "* -> 14

native

<:BigInteger

Whether the receiver is less than the BigInteger argument. The one native comparison -- >, <= and >= derive from it.

native

==:

Whether the argument is an equal BigInteger. Any other type is simply unequal, never an error -- including a plain Integer of the same value.

(BigInteger.of:2) == (BigInteger.of:2)     "* -> true
(BigInteger.of:2) == 2                     "* -> false

native

abs

The absolute value.

(BigInteger.of:'-7').abs     "* -> 7

native

asDouble

Convert to a Double, losing precision beyond a Double's ~15-17 significant digits.

(BigInteger.of:'12345678901234567890').asDouble     "* -> 12345678901234567000

native

asInteger

Narrow to a 64-bit Integer; raises an ArithmeticError if the value does not fit.

(BigInteger.of:42).asInteger     "* -> 42

native

pow:Integer

The receiver raised to a non-negative Integer exponent, at full precision. A negative exponent raises an ArithmeticError: there is no fractional escape from the integer domain.

(BigInteger.of:2).pow:100     "* -> 1267650600228229401496703205376

native

s

The value as decimal digits, with a leading - when negative.

native