std.internal.math.biguintcore

Fundamental operations for arbitrary-precision arithmetic

These functions are for internal use only.

Types 3

aliasmultibyteAdd = multibyteAddSub!('+')
aliasmultibyteSub = multibyteAddSub!('-')
structBigUint

BigUint performs memory management and wraps the low-level calls.

Fields
immutable(BigDigit) [] data
/* computed */ trustedAssumeUnique
Methods
size_t uintLength() @property pure nothrow const @safe @nogc scope
size_t ulongLength() @property pure nothrow const @safe @nogc scope
ulong peekUlong(size_t n) pure nothrow const @safe @nogc scope
uint peekUint(size_t n) pure nothrow const @safe @nogc scope
void opAssign(Tulong)(Tulong u) if (is (Tulong == ulong)) pure nothrow @safe scope
void opAssign(Tdummy = void)(BigUint y) pure nothrow @nogc @safe scope
int opCmp(Tdummy = void)(const BigUint y) pure nothrow @nogc const @safe scope
int opCmp(Tulong)(Tulong y) if (is (Tulong == ulong)) pure nothrow @nogc const @safe scope
bool opEquals(Tdummy = void)(ref const BigUint y) pure nothrow @nogc const @safe scope
bool opEquals(Tdummy = void)(ulong y) pure nothrow @nogc const @safe scope
bool isZero() pure const nothrow @safe @nogc scope
size_t numBytes() pure nothrow const @safe @nogc scope
char [] toDecimalString(int frontExtraBytes) const pure nothrow @safe scope
char [] toHexString(int frontExtraBytes, char separator = 0, int minPadding = 0, char padChar = '0', LetterCase letterCase = LetterCase.upper) const pure nothrow @safe scopeConvert to a hex string, printing a minimum number of digits 'minPadding', allocating an additional 'frontExtraBytes' at the start of the string. Padding is done with padChar, which may be '0' or '...
char[] toOctalString() pure nothrow @safe const scopeConvert to an octal string.
bool fromHexString(Range)(Range s) if (isBidirectionalRange!Range && isSomeChar!(ElementType!Range)) scope
bool fromDecimalString(Range)(Range s) if (isForwardRange!Range && isSomeChar!(ElementType!Range)) scope
void fromMagnitude(Range)(Range magnitude) if (isInputRange!Range && (isForwardRange!Range || hasLength!Range) && isUnsigned!(ElementType!Range)) scope
BigUint opBinary(string op, Tulong)(Tulong y) if (op == ">>" && is (Tulong == ulong)) pure nothrow @safe const return scope
BigUint opBinary(string op, Tulong)(Tulong y) if (op == "<<" && is (Tulong == ulong)) pure nothrow @safe const scope
BigUint addOrSubInt(Tulong)(const scope BigUint x, Tulong y, bool wantSub, ref bool sign) if (is(Tulong == ulong)) pure nothrow @safe
BigUint addOrSub(scope BigUint x, scope BigUint y, bool wantSub, ref bool sign) pure nothrow @safe
BigUint mulInt(T = ulong)(BigUint x, T y) pure nothrow @safe
BigUint mul(scope BigUint x, scope BigUint y) pure nothrow @safe
BigUint divInt(T)(return scope BigUint x, T y_) if ( is(immutable T == immutable uint) ) pure nothrow @safe
BigUint divInt(T)(scope BigUint x, T y) if ( is(immutable T == immutable ulong) ) pure nothrow @safe
uint modInt(T)(scope BigUint x, T y_) if ( is(immutable T == immutable uint) ) pure
BigUint div(return scope BigUint x, scope BigUint y) pure nothrow @safe
BigUint mod(return scope BigUint x, scope BigUint y) pure nothrow @safe
void divMod(BigUint x, scope BigUint y, out BigUint quotient, out BigUint remainder) pure nothrow @safe
BigUint bitwiseOp(string op)(scope BigUint x, scope BigUint y, bool xSign, bool ySign, ref bool resultSign) if (op == "|" || op == "^" || op == "&") pure nothrow @safe
BigUint pow(return scope BigUint x, ulong y) pure nothrow @safeReturn a BigUint which is x raised to the power of y. Method: Powers of 2 are removed from x, then left-to-right binary exponentiation is used. Memory allocation is minimized: at most one temporary...
size_t toHash() const @nogc nothrow pure @safe scope
Constructors
this(return scope immutable(BigDigit) [] x)
this(T x)

Functions 37

fnsize_t getCacheLimit() @nogc nothrow pure @safe
fninout(BigDigit) [] removeLeadingZeros(return scope inout(BigDigit) [] x) pure nothrow @safe
fnvoid twosComplement(const(BigDigit) [] x, BigDigit[] result) pure nothrow @safe
fnBigDigit[] includeSign(scope const(BigDigit) [] x, size_t minSize, bool sign) pure nothrow @safe
fnT intpow(T)(T x, ulong n) pure nothrow @safe
fnint highestPowerBelowUintMax(uint x) pure nothrow @safe
fnint highestPowerBelowUlongMax(uint x) pure nothrow @safe
fnBigDigit [] sub(const scope BigDigit [] x, const scope BigDigit [] y, bool * negative) pure nothrow @safe
fnBigDigit [] add(const scope BigDigit [] a, const scope BigDigit [] b) pure nothrow @safe
fnBigDigit [] addInt(const BigDigit[] x, ulong y) @safe pure nothrowreturn x + y
fnBigDigit [] subInt(const BigDigit[] x, ulong y) pure nothrow @safeReturn x - y. x must be greater than y.
fnvoid mulInternal(BigDigit[] result, const(BigDigit)[] x, const(BigDigit)[] y) pure nothrow @safeGeneral unsigned multiply routine for bigints. Sets result = x * y.
fnvoid squareInternal(BigDigit[] result, const BigDigit[] x) pure nothrow @safeGeneral unsigned squaring routine for BigInts. Sets result = x*x. NOTE: If the highest half-digit of x is zero, the highest digit of result will also be zero.
fnvoid divModInternal(BigDigit [] quotient, BigDigit[] remainder, const BigDigit [] u, const BigDigit [] v) pure nothrow @safeif remainder is null, only calculate quotient.
fnchar [] biguintToHex(return scope char [] buff, const scope BigDigit [] data, char separator = 0, LetterCase letterCase = LetterCase.upper) pure nothrow @safe
fnsize_t biguintToOctal(char[] buff, const(BigDigit)[] data) pure nothrow @safe @nogcConvert a big uint into an octal string.
fnsize_t biguintToDecimal(char [] buff, BigDigit [] data) pure nothrow @safeConvert a big uint into a decimal string.
fnint biguintFromDecimal(Range)(BigDigit[] data, Range s) if ( isInputRange!Range && isSomeChar!(ElementType!Range) && !isInfinite!Range)Convert a decimal string into a big uint.
fnvoid mulSimple(BigDigit[] result, const(BigDigit) [] left, const(BigDigit)[] right) pure nothrow @safe
fnvoid squareSimple(BigDigit[] result, const(BigDigit) [] x) pure nothrow @safe
fnuint addSimple(BigDigit[] result, const BigDigit [] left, const BigDigit [] right) pure nothrow @safe
fnBigDigit subAssignSimple(BigDigit [] result, const(BigDigit) [] right) pure nothrow @safe
fnBigDigit addAssignSimple(BigDigit [] result, const(BigDigit) [] right) pure nothrow @safe
fnBigDigit addOrSubAssignSimple(BigDigit [] result, const(BigDigit) [] right, bool wantSub) pure nothrow @safe
fnbool less(const(BigDigit)[] x, const(BigDigit)[] y) pure nothrow @safe
fnbool inplaceSub(BigDigit[] result, const(BigDigit)[] x, const(BigDigit)[] y) pure nothrow @safe
fnsize_t karatsubaRequiredBuffSize(size_t xlen) pure nothrow @safe
fnvoid mulKaratsuba(BigDigit [] result, const(BigDigit) [] x, const(BigDigit)[] y, BigDigit [] scratchbuff) pure nothrow @safe
fnvoid squareKaratsuba(BigDigit [] result, const BigDigit [] x, BigDigit [] scratchbuff) pure nothrow @safe
fnvoid schoolbookDivMod(BigDigit [] quotient, BigDigit [] u, in BigDigit [] v) pure nothrow @safe
fnvoid itoaZeroPadded(char[] output, uint value) pure nothrow @safe @nogc
fnvoid toHexZeroPadded(char[] output, uint value, LetterCase letterCase = LetterCase.upper) pure nothrow @safe
fnsize_t highestDifferentDigit(const BigDigit [] left, const BigDigit [] right) pure nothrow @nogc @safe
fnint firstNonZeroDigit(const BigDigit [] x) pure nothrow @nogc @safe
fnvoid recursiveDivMod(BigDigit[] quotient, BigDigit[] u, const(BigDigit)[] v, BigDigit[] scratch, bool mayOverflow = false) pure nothrow @safe
fnvoid adjustRemainder(BigDigit[] quot, BigDigit[] rem, const(BigDigit)[] v, ptrdiff_t k, BigDigit[] scratch, bool mayOverflow = false) pure nothrow @safe
fnvoid blockDivMod(BigDigit [] quotient, BigDigit [] u, in BigDigit [] v) pure nothrow @safe

Variables 6

enumvarFASTDIVLIMIT = 100
enumvarBigDigitBits = BigDigit.sizeof * 8
varBigDigit[] ZERO
varBigDigit[] ONE
varBigDigit[] TWO
varBigDigit[] TEN

Templates 1

tmplmaxBigDigits(T) if (isIntegral!T)