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 (>>>).
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.
- static BigInt
opCall
(char[] s);
- 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.
- void
opAssign
(T : int)(T x);
- BigInt
opAdd
(T : int)(T y);
- BigInt
opAddAssign
(T : int)(T y);
- BigInt
opAdd
(T : BigInt )(T y);
- BigInt
opAddAssign
(T : BigInt )(T y);
- BigInt
opSub
(T : int)(T y);
- BigInt
opSubAssign
(T : int)(T y);
- BigInt
opSub
(T : BigInt )(T y);
- BigInt
opSubAssign
(T : BigInt )(T y);
- BigInt
opMul
(T : int)(T y);
- BigInt
opMulAssign
(T : int)(T y);
- BigInt
opMul
(T : BigInt )(T y);
- BigInt
opMulAssign
(T : BigInt )(T y);
- BigInt
opDiv
(T : int)(T y);
- BigInt
opDivAssign
(T : int)(T y);
- BigInt
opDivAssign
(T : BigInt )(T y);
- BigInt
opDiv
(T : BigInt )(T y);
- int
opMod
(T : int)(T y);
- BigInt
opModAssign
(T : int)(T y);
- BigInt
opMod
(T : BigInt )(T y);
- BigInt
opModAssign
(T : BigInt )(T y);
- BigInt
opNeg
();
- BigInt
opPos
();
- BigInt
opPostInc
();
- BigInt
opPostDec
();
- BigInt
opShr
(T : int)(T y);
- BigInt
opShrAssign
(T : int)(T y);
- BigInt
opShl
(T : int)(T y);
- BigInt
opShlAssign
(T : int)(T y);
- int
opEquals
(BigInt y);
- int
opCmp
(BigInt y);
- int
numBytes
();
- BUG:
For testing only, this will be removed eventually
- char[]
toDecimalString
();
- BUG:
For testing only, this will be removed eventually
- char[]
toHex
();
- Convert to a hexadecimal string, with an underscore every
8 characters.
|