tango.math.BigInt

Arbitrary-precision ('bignum') arithmetic

License:

BSD style: see license.txt

Authors:

Don Clugston
struct BigInt #
A struct representing an arbitrary precision integer
All arithmetic operations are supported, except unsigned shift right (>>>). Reverse operations are supported only for int, long, and ulong, due to language limitations. It implements value semantics using copy-on-write. This means that assignment is cheap, but operations such as x++ will cause heap allocation. (But note that for most bigint operations, heap allocation is inevitable anyway).

Performance is excellent for numbers below ~1000 decimal digits. For X86 machines, highly optimised assembly routines are used.

BigInt opCall(T : char[])(T z) [public, static] #
Construct a BigInt from a decimal or hexadecimal string. The number must be in the form of a D decimal or hex literal: It may have a leading + or - sign; followed by "0x" if hexadecimal. Underscores are permitted.

BUG:

Should throw a IllegalArgumentException/ConvError if invalid character found
void opAssign(T : int)(T x) [public] #
BigInt opAdd(T : int)(T y) [public] #
BigInt opAddAssign(T : int)(T y) [public] #
BigInt opAdd(T : BigInt)(T y) [public] #
BigInt opAddAssign(T : BigInt)(T y) [public] #
BigInt opSub(T : int)(T y) [public] #
BigInt opSubAssign(T : int)(T y) [public] #
BigInt opSub(T : BigInt)(T y) [public] #
BigInt opSub_r(int y) [public] #
BigInt opSub_r(long y) [public] #
BigInt opSub_r(ulong y) [public] #
BigInt opSubAssign(T : BigInt)(T y) [public] #
BigInt opMul(T : int)(T y) [public] #
BigInt opMulAssign(T : int)(T y) [public] #
BigInt opMul(T : BigInt)(T y) [public] #
BigInt opMulAssign(T : BigInt)(T y) [public] #
BigInt opDiv(T : int)(T y) [public] #
BigInt opDivAssign(T : int)(T y) [public] #
BigInt opDivAssign(T : BigInt)(T y) [public] #
BigInt opDiv(T : BigInt)(T y) [public] #
int opMod(T : int)(T y) [public] #
BigInt opModAssign(T : int)(T y) [public] #
BigInt opMod(T : BigInt)(T y) [public] #
BigInt opModAssign(T : BigInt)(T y) [public] #
BigInt opNeg() [public] #
BigInt opPos() [public] #
BigInt opPostInc() [public] #
BigInt opPostDec() [public] #
BigInt opShr(T : int)(T y) [public] #
BigInt opShrAssign(T : int)(T y) [public] #
BigInt opShl(T : int)(T y) [public] #
BigInt opShlAssign(T : int)(T y) [public] #
int opEquals(T : BigInt)(T y) [public] #
int opEquals(T : int)(T y) [public] #
int opCmp(T : int)(T y) [public] #
int opCmp(T : BigInt)(T y) [public] #
long toLong() [public] #
Returns the value of this BigInt as a long, or +- long.max if outside the representable range.
long toInt() [public] #
Returns the value of this BigInt as an int, or +- long.max if outside the representable range.
int uintLength() [public] #
Number of significant uints which are used in storing this number. The absolute value of this BigInt is always < 2^(32*uintLength)
int ulongLength() [public] #
Number of significant ulongs which are used in storing this number. The absolute value of this BigInt is always < 2^(64*ulongLength)
BigInt pow(BigInt x, ulong y) [public, static] #
Return x raised to the power of y This interface is tentative and may change.
int numBytes() [public] #
Deprecated. Use uintLength() or ulongLength() instead.
char [] toDecimalString() [public] #

BUG:

For testing only, this will be removed eventually (needs formatting options)
char [] toHex() [public] #
Convert to a hexadecimal string, with an underscore every 8 characters.
BigInt sliceHighestBytes(uint numbytes) [package] #

BUG:

For testing only, this will be removed eventually