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.

Members

Functions

isNegative
bool isNegative()
Undocumented in source. Be warned that the author may not have intended to support it.
isZero
bool isZero()
Undocumented in source. Be warned that the author may not have intended to support it.
negate
void negate()
Undocumented in source. Be warned that the author may not have intended to support it.
numBytes
int numBytes()

Deprecated. Use uintLength() or ulongLength() instead.

opAdd
BigInt opAdd(T y)
opAdd
BigInt opAdd(T y)
opAddAssign
BigInt opAddAssign(T y)
opAddAssign
BigInt opAddAssign(T y)
opAssign
void opAssign(T x)
opCmp
int opCmp(T y)
opCmp
int opCmp(T y)
opDiv
BigInt opDiv(T y)
opDiv
BigInt opDiv(T y)
opDivAssign
BigInt opDivAssign(T y)
opDivAssign
BigInt opDivAssign(T y)
opEquals
int opEquals(T y)
opEquals
int opEquals(T y)
opMod
int opMod(T y)
opMod
BigInt opMod(T y)
opModAssign
BigInt opModAssign(T y)
opModAssign
BigInt opModAssign(T y)
opMul
BigInt opMul(T y)
opMul
BigInt opMul(T y)
opMulAssign
BigInt opMulAssign(T y)
opMulAssign
BigInt opMulAssign(T y)
opNeg
BigInt opNeg()
opPos
BigInt opPos()
opPostDec
BigInt opPostDec()
opPostInc
BigInt opPostInc()
opShl
BigInt opShl(T y)
opShlAssign
BigInt opShlAssign(T y)
opShr
BigInt opShr(T y)
opShrAssign
BigInt opShrAssign(T y)
opSub
BigInt opSub(T y)
opSub
BigInt opSub(T y)
opSubAssign
BigInt opSubAssign(T y)
opSubAssign
BigInt opSubAssign(T y)
opSub_r
BigInt opSub_r(int y)
opSub_r
BigInt opSub_r(long y)
opSub_r
BigInt opSub_r(ulong y)
sliceHighestBytes
BigInt sliceHighestBytes(uint numbytes)

BUG: For testing only, this will be removed eventually

toDecimalString
char[] toDecimalString()

BUG: For testing only, this will be removed eventually (needs formatting options)

toHex
char[] toHex()

Convert to a hexadecimal string, with an underscore every 8 characters.

toInt
long toInt()

Returns the value of this BigInt as an int, or +- long.max if outside the representable range.

toLong
long toLong()

Returns the value of this BigInt as a long, or +- long.max if outside the representable range.

uintLength
int uintLength()

Number of significant uints which are used in storing this number. The absolute value of this BigInt is always < 2^(32*uintLength)

ulongLength
int ulongLength()

Number of significant ulongs which are used in storing this number. The absolute value of this BigInt is always < 2^(64*ulongLength)

Static functions

opCall
BigInt opCall(const(T) z)

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

opCall
BigInt opCall(T x)
Undocumented in source. Be warned that the author may not have intended to support it.
pow
BigInt pow(BigInt x, ulong y)

Return x raised to the power of y This interface is tentative and may change.

Meta