Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
mir.bignum.internal.phobos_kernel
Fundamental operations for arbitrary-precision arithmetic
These functions are for internal use only.
- package(mir.bignum) pure nothrow @nogc @safe void
mulInternal(BigDigit[]result, const(BigDigit)[]x, const(BigDigit)[]y, BigDigit[]scratchbuff); - General unsigned multiply routine for bigints. Sets result = x * y.The length of y must not be larger than the length of x. Different algorithms are used, depending on the lengths of x and y.
TODO "Modern Computer Arithmetic" suggests the OddEvenKaratsuba algorithm for the unbalanced case. (But I doubt it would be faster in practice).
- package(mir.bignum) pure nothrow @nogc @safe void
squareInternal(BigDigit[]result, const BigDigit[]x, BigDigit[]scratchbuff); - General 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.
- package(mir.bignum) pure nothrow @nogc @safe void
divModInternal(BigDigit[]quotient, BigDigit[]remainder, const BigDigit[]u, const BigDigit[]v, BigDigit[]buffer); - if remainder is null, only calculate quotient.
- package(mir.bignum) pure nothrow @nogc @safe size_t
biguintToOctal(char[]buff, const(BigDigit)[]data); - Convert a big uint into an octal string.Parameters:
char[] buffThe destination buffer for the octal string. Must be large enough to store the result, including leading zeroes, which is ceil(data.length * BigDigitBits / 3) characters. The buffer is filled from back to front, starting from buff[$-1].const(BigDigit)[] dataThe biguint to be converted. Returns:The index of the leading non-zero digit inbuff. Will bebuff.length - 1 if the entire big uint is zero. - package(mir.bignum) pure nothrow @nogc @safe size_t
biguintToDecimal(char[]buff, BigDigit[]data); - Convert a big uint into a decimal string.Parameters:
char[] buffThe destination buffer for the decimal string. Must be large enough to store the result, including leading zeros. Will be filled backwards, starting from buff[$-1]. BigDigit[] dataThe biguint to be converted. Will be destroyed. buff.length must be >= (data.length*32)/log2(10) = 9.63296 * data.length. Returns:the lowest index of buff which was used. - int
biguintFromDecimal(Range)(BigDigit[]data, Ranges)
if (isInputRange!Range && isSomeChar!(ElementType!Range) && !isInfinite!Range); - Convert a decimal string into a big uint.Parameters:
BigDigit[] dataThe biguint to be receive the result. Must be large enough to store the result. Range sThe decimal string. May contain or 0 .. 9 The required length for the destination buffer is slightly less than 1 + s.length/log2(10) = 1 + s.length/3.3219. Returns:the highest index of data which was used. 0 if case of failure.
Copyright © 2016-2026 by Ilya Yaroshenko | Page generated by
Ddoc on Wed Apr 8 13:47:03 2026