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.low_level_view

Low-level betterC utilities for big integer arithmetic libraries.

Note The module doesn't provide full arithmetic API for now.

enum WordEndian: int;
little
big
enum WordEndian TargetEndian;
pure nothrow @nogc @safe T ceilLog10Exp2(T)(const T e)
if (is(T == ubyte) || is(T == ushort) || is(T == uint) || is(T == ulong));
Fast integer computation of ceil(log10(exp2(e))) with 64-bit mantissa precision. The result is guaranted to be greater then log10(exp2(e)), which is irrational number.
Examples:
assert(ceilLog10Exp2(ubyte(10)) == 4); // ubyte
assert(ceilLog10Exp2(10U) == 4); // uint
assert(ceilLog10Exp2(10UL) == 4); // ulong
struct BigUIntView(W, WordEndian endian = TargetEndian) if (__traits(isUnsigned, W));
Arbitrary length unsigned integer view.
Examples:
import std.traits;
alias AliasSeq(T...) = T;

foreach (T; AliasSeq!(ubyte, ushort, uint, ulong))
foreach (endian; AliasSeq!(WordEndian.little, WordEndian.big))
{
    static if (endian == WordEndian.little)
    {
        T[3] lhsData = [1, T.max-1, 0];
        T[3] rhsData = [T.max, T.max, 0];
    }
    else
    {
        T[3] lhsData = [0, T.max-1, 1];
        T[3] rhsData = [0, T.max, T.max];
    }

    auto lhs = BigUIntView!(T, endian)(lhsData).normalized;

    /// bool overflow = bigUInt op= scalar
    assert(lhs.leastSignificantFirst == [1, T.max-1]);
    assert(lhs.mostSignificantFirst == [T.max-1, 1]);
    static if (T.sizeof >= 4)
    {
        assert((lhs += T.max) == false);
        assert(lhs.leastSignificantFirst == [0, T.max]);
        assert((lhs += T.max) == false);
        assert((lhs += T.max) == true); // overflow bit
        assert(lhs.leastSignificantFirst == [T.max-1, 0]);
        assert((lhs -= T(1)) == false);
        assert(lhs.leastSignificantFirst == [T.max-2, 0]);
        assert((lhs -= T.max) == true); // underflow bit
        assert(lhs.leastSignificantFirst == [T.max-1, T.max]);
        assert((lhs -= Signed!T(-4)) == true); // overflow bit
        assert(lhs.leastSignificantFirst == [2, 0]);
        assert((lhs += Signed!T.max) == false); // overflow bit
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0]);

        ///  bool overflow = bigUInt op= bigUInt/bigInt
        lhs = BigUIntView!(T, endian)(lhsData);
        auto rhs = BigUIntView!(T, endian)(rhsData).normalized;
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
        assert(rhs.leastSignificantFirst == [T.max, T.max]);
        assert((lhs += rhs) == false);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 1, 0, 1]);
        assert((lhs -= rhs) == false);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
        assert((lhs += -rhs) == true);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 3, 0, T.max]);
        assert((lhs += -(-rhs)) == true);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);

        /// W overflow = bigUInt *= scalar
        assert((lhs *= T.max) == 0);
        assert((lhs += T(Signed!T.max + 2)) == false);
        assert(lhs.leastSignificantFirst == [0, Signed!T.max + 2, 0]);
        lhs = lhs.normalized;
        lhs.leastSignificantFirst[1] = T.max / 2 + 3;
        assert(lhs.leastSignificantFirst == [0, T.max / 2 + 3]);
        assert((lhs *= 8u) == 4);
        assert(lhs.leastSignificantFirst == [0, 16]);
    }
}
W[] coefficients;
A group of coefficients for a radix W.max + 1.
The order corresponds to endianness.
pure nothrow @nogc @property scope @safe BigIntView!(W, endian) signed()();

Retrurns signed integer view using the same data payload

const scope T opCast(T, bool wordNormalized = false, bool nonZero = false)()
if (isFloatingPoint!T && isMutable!T);
Examples:
auto a = cast(double) BigUIntView!size_t.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
assert(a == 0xa.fbbfae3cd0bp+124);
assert(cast(double) BigUIntView!size_t.init == 0);
assert(cast(double) BigUIntView!size_t([0]) == 0);
const scope @safe T opCast(T : Fp!coefficientSize, size_t internalRoundLastBits = 0, bool wordNormalized = false, bool nonZero = false, size_t coefficientSize)()
if (internalRoundLastBits < size_t.sizeof * 8 && (size_t.sizeof >= W.sizeof || endian == TargetEndian));
Examples:
import mir.bignum.fp: Fp;
import mir.bignum.fixed: UInt;

auto fp = cast(Fp!128) BigUIntView!ulong.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
assert(fp.exponent == 0);
assert(fp.coefficient == UInt!128.fromHexString("afbbfae3cd0aff2714a1de7022b0029d"));

fp = cast(Fp!128) BigUIntView!uint.fromHexString("ae3cd0aff2714a1de7022b0029d");
assert(fp.exponent == -20);
assert(fp.coefficient == UInt!128.fromHexString("ae3cd0aff2714a1de7022b0029d00000"));

fp = cast(Fp!128) BigUIntView!ushort.fromHexString("e7022b0029d");
assert(fp.exponent == -84);
assert(fp.coefficient == UInt!128.fromHexString("e7022b0029d000000000000000000000"));

fp = cast(Fp!128) BigUIntView!ubyte.fromHexString("e7022b0029d");
assert(fp.exponent == -84);
assert(fp.coefficient == UInt!128.fromHexString("e7022b0029d000000000000000000000"));

fp = cast(Fp!128) BigUIntView!size_t.fromHexString("e7022b0029d");
assert(fp.exponent == -84);
assert(fp.coefficient == UInt!128.fromHexString("e7022b0029d000000000000000000000"));

fp = cast(Fp!128) BigUIntView!size_t.fromHexString("ffffffffffffffffffffffffffffffff1000000000000000");
assert(fp.exponent == 64);
assert(fp.coefficient == UInt!128.fromHexString("ffffffffffffffffffffffffffffffff"));

fp = cast(Fp!128) BigUIntView!size_t.fromHexString("ffffffffffffffffffffffffffffffff8000000000000000");
assert(fp.exponent == 65);
assert(fp.coefficient == UInt!128.fromHexString("80000000000000000000000000000000"));

fp = cast(Fp!128) BigUIntView!size_t.fromHexString("fffffffffffffffffffffffffffffffe8000000000000000");
assert(fp.exponent == 64);
assert(fp.coefficient == UInt!128.fromHexString("fffffffffffffffffffffffffffffffe"));

fp = cast(Fp!128) BigUIntView!size_t.fromHexString("fffffffffffffffffffffffffffffffe8000000000000001");
assert(fp.exponent == 64);
assert(fp.coefficient == UInt!128.fromHexString("ffffffffffffffffffffffffffffffff"));
const scope T opCast(T, bool nonZero = false)()
if (isIntegral!T && isUnsigned!T && isMutable!T);
Examples:
auto view = BigUIntView!ulong.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
assert(cast(ulong) view == 0x14a1de7022b0029d);
assert(cast(uint) view == 0x22b0029d);
assert(cast(ubyte) view == 0x9d);
pure nothrow @nogc scope @trusted BigUIntView!V opCast(T : BigUIntView!V, V)() return
if (V.sizeof <= W.sizeof);
const pure nothrow @nogc @property scope @safe BigUIntView!(const(W), endian) lightConst()() return;
const pure nothrow @nogc scope @safe sizediff_t opCmp(scope BigUIntView!(const(W), endian) rhs);
const pure nothrow @nogc scope @safe bool opEquals(scope BigUIntView!(const(W), endian) rhs);
inout @property ref scope inout(W) mostSignificant() return;
inout @property ref scope inout(W) leastSignificant() return;
scope void popMostSignificant();
scope void popLeastSignificant();
scope BigUIntView topMostSignificantPart(size_t length) return;
scope BigUIntView topLeastSignificantPart(size_t length) return;
scope void smallLeftShiftInPlace()(uint shift);
Shifts left using at most size_t.sizeof * 8 - 1 bits
Examples:
auto a = BigUIntView!size_t.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
a.smallLeftShiftInPlace(4);
assert(a == BigUIntView!size_t.fromHexString("fbbfae3cd0aff2714a1de7022b0029d0"));
a.smallLeftShiftInPlace(0);
assert(a == BigUIntView!size_t.fromHexString("fbbfae3cd0aff2714a1de7022b0029d0"));
void smallRightShiftInPlace()(uint shift);
Shifts right using at most size_t.sizeof * 8 - 1 bits
Examples:
auto a = BigUIntView!size_t.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
a.smallRightShiftInPlace(4);
assert(a == BigUIntView!size_t.fromHexString("afbbfae3cd0aff2714a1de7022b0029"));
pure @trusted BigUIntView fromHexString(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
pure nothrow @nogc scope @safe bool fromHexStringImpl(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
Examples:
auto view = BigUIntView!size_t.fromHexString!(char, true)("abcd_efab_cdef");
assert(cast(ulong)view == 0xabcd_efab_cdef);
Examples:
// Check that invalid underscores in hex literals throw an error.
void expectThrow(const(char)[] input) {
    bool caught = false;
    try { 
        auto view = BigUIntView!size_t.fromHexString!(char, true)(input);
    } catch (Exception e) {
        caught = true;
    }

    assert(caught);
}

expectThrow("abcd_efab_cef_");
expectThrow("abcd__efab__cef");
expectThrow("_abcd_efab_cdef");
expectThrow("_abcd_efab_cdef_");
expectThrow("_abcd_efab_cdef__");
expectThrow("__abcd_efab_cdef");
expectThrow("__abcd_efab_cdef_");
expectThrow("__abcd_efab_cdef__");
expectThrow("__abcd__efab_cdef__");
expectThrow("__abcd__efab__cdef__");
pure @trusted BigUIntView fromBinaryString(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
pure nothrow @nogc scope @safe bool fromBinaryStringImpl(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
Examples:
auto view = BigUIntView!size_t.fromBinaryString!(char, true)("1111_0000_0101");
assert(cast(ulong)view == 0b1111_0000_0101);
Examples:
// Check that invalid underscores in hex literals throw an error.
void expectThrow(const(char)[] input) {
    bool caught = false;
    try { 
        auto view = BigUIntView!size_t.fromBinaryString!(char, true)(input);
    } catch (Exception e) {
        caught = true;
    }

    assert(caught);
}

expectThrow("abcd");
expectThrow("0101__1011__0111");
expectThrow("_0101_1011_0111");
expectThrow("_0101_1011_0111_");
expectThrow("_0101_1011_0111__");
expectThrow("__0101_1011_0111_");
expectThrow("__0101_1011_0111__");
expectThrow("__0101__1011_0111__");
expectThrow("__1011__0111__1011__");
pure nothrow @nogc scope @trusted bool fromStringImpl(C)(scope const(C)[] str)
if (isSomeChar!C);
Returns:
false in case of overflow or incorrect string.

Precondition non-empty coefficients

Note doesn't support signs.

pure nothrow @nogc scope @safe bool opOpAssign(string op)(scope BigUIntView!(const(W), endian) rhs, bool overflow = false)
if (op == "+" || op == "-");

pure nothrow @nogc scope @safe bool opOpAssign(string op)(scope BigIntView!(const(W), endian) rhs, bool overflow = false)
if (op == "+" || op == "-");
Performs bool overflow = big +(-)= big operatrion.
Parameters:
BigUIntView!(const(W), endian) rhs value to add with non-empty coefficients
bool overflow (overflow) initial iteration overflow

Precondition non-empty coefficients length of greater or equal to the rhs coefficients length.

Returns:
true in case of unsigned overflow
pure nothrow @nogc scope @safe bool opOpAssign(string op, T)(const T rhs)
if ((op == "+" || op == "-") && is(T == W));

pure nothrow @nogc scope @safe bool opOpAssign(string op, T)(const T rhs)
if ((op == "+" || op == "-") && is(T == Signed!W));
Performs bool Overflow = big +(-)= scalar operatrion.

Precondition non-empty coefficients

Parameters:
T rhs value to add
Returns:
true in case of unsigned overflow
pure nothrow @nogc scope @safe W opOpAssign(string op : "*")(W rhs, W overflow = 0u);
Performs W overflow = (big += overflow) *= scalar operatrion.

Precondition non-empty coefficients

Parameters:
W rhs unsigned value to multiply by
W overflow initial overflow
Returns:
unsigned overflow value
pure nothrow @nogc scope @safe uint opOpAssign(string op : "/")(uint rhs, uint overflow = 0);
Performs uint remainder = (overflow$big) /= scalar operatrion, where $ denotes big-endian concatenation.

Precondition non-empty coefficients, overflow < rhs

Parameters:
uint rhs unsigned value to devide by
uint overflow initial unsigned overflow
Returns:
unsigned remainder value (evaluated overflow)
pure nothrow @nogc scope @safe UInt!size opOpAssign(string op : "*", size_t size)(UInt!size rhs, UInt!size overflow = 0);
Performs W overflow = (big += overflow) *= scalar operatrion.

Precondition non-empty coefficients

Parameters:
UInt!size rhs unsigned fixed-length integer to multiply by
UInt!size overflow initial overflow
Returns:
unsigned fixed-length integer overflow value
scope BigIntView!(W, endian) opUnary(string op : "-")() return;
Returns:
the same intger view with inversed sign
scope void bitwiseNotInPlace();
scope bool twoComplementInPlace();
Performs number=-number operatrion.

Precondition non-empty coefficients

Returns:
true if 'number=-number=0' and false otherwise
pure nothrow @nogc @property scope @safe auto leastSignificantFirst() return;
Returns:
a slice of coefficients starting from the least significant.
const pure nothrow @nogc @property scope @safe auto leastSignificantFirst() return;
pure nothrow @nogc @property scope @safe auto mostSignificantFirst() return;
Returns:
a slice of coefficients starting from the most significant.
const pure nothrow @nogc @property scope @safe auto mostSignificantFirst() return;
scope BigUIntView normalized() return;

const scope BigUIntView!(const(W), endian) normalized();
Strips most significant zero coefficients.
scope bool bt()(size_t position);
const pure nothrow @nogc @property scope @safe size_t ctlz()();
const pure nothrow @nogc @property scope @safe size_t cttz()();
BigIntView!(W, endian) withSign()(bool sign);
const pure nothrow @nogc scope @safe bool get(U)(out scope U value)
if (isUnsigned!U);
Parameters:
U value (out) unsigned integer
Returns:
true on success
const pure nothrow @nogc scope @safe bool opEquals(ulong rhs);
Returns:
true if the integer and equals to rhs.
Examples:
auto view2 = BigUIntView!(const(ubyte), WordEndian.big)([1, 0]);
assert(view2 == 256); // false
assert(cast(ulong)view2 == 256); // true
auto view = BigUIntView!(const(ubyte), WordEndian.big)([15, 255, 255]);
assert(view == 1048575); // false
assert(cast(ulong)view == 1048575); // true
pure nothrow @nogc @safe size_t toStringImpl(C)(scope C[] str)
if (isSomeChar!C && isMutable!C);
Parameters:
C[] str string buffer, the tail paer

Precondition mutable number with word size at least 4 bytes

Postconditoin the number is destroyed

Returns:
last N bytes used in the buffer
Examples:
import mir.bignum.integer;

auto a = BigInt!2("123456789098765432123456789098765432100");
char[ceilLog10Exp2(a.data.length * (size_t.sizeof * 8))] buffer;
auto len = a.view.unsigned.toStringImpl(buffer);
assert(buffer[$ - len .. $] == "123456789098765432123456789098765432100");
struct BigIntView(W, WordEndian endian = TargetEndian) if (is(Unqual!W == ubyte) || is(Unqual!W == ushort) || is(Unqual!W == uint) || is(Unqual!W == ulong));
Arbitrary length signed integer view.
Examples:
import std.traits;
alias AliasSeq(T...) = T;

foreach (T; AliasSeq!(ubyte, ushort, uint, ulong))
foreach (endian; AliasSeq!(WordEndian.little, WordEndian.big))
{
    static if (endian == WordEndian.little)
    {
        T[3] lhsData = [1, T.max-1, 0];
        T[3] rhsData = [T.max, T.max, 0];
    }
    else
    {
        T[3] lhsData = [0, T.max-1, 1];
        T[3] rhsData = [0, T.max, T.max];
    }

    auto lhs = BigIntView!(T, endian)(lhsData).normalized;

    ///  bool overflow = bigUInt op= scalar
    assert(lhs.leastSignificantFirst == [1, T.max-1]);
    assert(lhs.mostSignificantFirst == [T.max-1, 1]);

    static if (T.sizeof >= 4)
    {

        assert((lhs += T.max) == false);
        assert(lhs.leastSignificantFirst == [0, T.max]);
        assert((lhs += T.max) == false);
        assert((lhs += T.max) == true); // overflow bit
        assert(lhs.leastSignificantFirst == [T.max-1, 0]);
        assert((lhs -= T(1)) == false);
        assert(lhs.leastSignificantFirst == [T.max-2, 0]);
        assert((lhs -= T.max) == false);
        assert(lhs.leastSignificantFirst == [2, 0]);
        assert(lhs.sign);
        assert((lhs -= Signed!T(-4)) == false);
        assert(lhs.leastSignificantFirst == [2, 0]);
        assert(lhs.sign == false);
        assert((lhs += Signed!T.max) == false);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0]);

        ///  bool overflow = bigUInt op= bigUInt/bigInt
        lhs = BigIntView!(T, endian)(lhsData);
        auto rhs = BigUIntView!(T, endian)(rhsData).normalized;
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
        assert(rhs.leastSignificantFirst == [T.max, T.max]);
        assert((lhs += rhs) == false);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 1, 0, 1]);
        assert((lhs -= rhs) == false);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
        assert((lhs += -rhs) == false);
        assert(lhs.sign);
        assert(lhs.leastSignificantFirst == [T.max - (Signed!T.max + 2), T.max, 0]);
        assert(lhs.sign);
        assert((lhs -= -rhs) == false);
        assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
        assert(lhs.sign == false);
    }
}
Examples:
import mir.bignum.fixed: UInt;
import mir.bignum.low_level_view: BigUIntView;
auto bigView = BigUIntView!size_t.fromHexString("55a325ad18b2a77120d870d987d5237473790532acab45da44bc07c92c92babf0b5e2e2c7771cd472ae5d7acdb159a56fbf74f851a058ae341f69d1eb750d7e3");
auto fixed = UInt!256.fromHexString("55e5669576d31726f4a9b58a90159de5923adc6c762ebd3c4ba518d495229072");
auto overflow = bigView *= fixed;
assert(overflow == UInt!256.fromHexString("1cbbe8c42dc21f936e4ce5b2f52ac404439857f174084012fcd1b71fdec2a398"));
assert(bigView == BigUIntView!size_t.fromHexString("c73fd2b26f2514c103c324943b6c90a05d2732118d5f0099c36a69a8051bb0573adc825b5c9295896c70280faa4c4d369df8e92f82bfffafe078b52ae695d316"));
Examples:
import mir.bignum.fixed: UInt;
import mir.bignum.low_level_view: BigUIntView;
auto bigView2 = BigUIntView!size_t.fromHexString("55a325ad18b2a77120d870d987d5237473790532acab45da44bc07c92c92babf0b5e2e2c7771cd472ae5d7acdb159a56fbf74f851a058ae341f69d1eb750d7e3");
auto bigView = BigUIntView!size_t.fromHexString!(char, true)("55a3_25ad_18b2_a771_20d8_70d9_87d5_2374_7379_0532_acab_45da_44bc_07c9_2c92_babf_0b5e_2e2c_7771_cd47_2ae5_d7ac_db15_9a56_fbf7_4f85_1a05_8ae3_41f6_9d1e_b750_d7e3");
auto fixed = UInt!256.fromHexString!(true)("55e5_6695_76d3_1726_f4a9_b58a_9015_9de5_923a_dc6c_762e_bd3c_4ba5_18d4_9522_9072");
auto overflow = bigView *= fixed;
assert(overflow == UInt!256.fromHexString("1cbbe8c42dc21f936e4ce5b2f52ac404439857f174084012fcd1b71fdec2a398"));
assert(bigView == BigUIntView!size_t.fromHexString("c73fd2b26f2514c103c324943b6c90a05d2732118d5f0099c36a69a8051bb0573adc825b5c9295896c70280faa4c4d369df8e92f82bfffafe078b52ae695d316"));
BigUIntView!(W, endian) unsigned;
Self-assigned to unsigned integer view BigUIntView..
Sign is stored in the most significant bit.
The number is encoded as pair of unsigned and sign.
bool sign;
Sign bit
inout @property scope inout(W)[] coefficients() return;
this(W[] coefficients, bool sign = false);
this(BigUIntView!(W, endian) unsigned, bool sign = false);
pure nothrow @nogc scope @trusted bool fromStringImpl(C)(scope const(C)[] str)
if (isSomeChar!C);
Returns:
false in case of overflow or incorrect string.

Precondition non-empty coefficients.

pure @trusted BigIntView fromHexString(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
pure nothrow @nogc @safe bool fromHexStringImpl(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
pure @trusted BigIntView fromBinaryString(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
pure nothrow @nogc @safe bool fromBinaryStringImpl(C, bool allowUnderscores = false)(scope const(C)[] str)
if (isSomeChar!C);
const scope T opCast(T, bool wordNormalized = false, bool nonZero = false)()
if (isFloatingPoint!T && isMutable!T);
Examples:
auto a = cast(double) BigIntView!size_t.fromHexString("-afbbfae3cd0aff2714a1de7022b0029d");
assert(a == -0xa.fbbfae3cd0bp+124);
Examples:
auto a = cast(double) BigIntView!size_t.fromBinaryString("-10101111101110111111101011100011110011010000101011111111001001110001010010100001110111100111000000100010101100000000001010011101");
assert(a == -0xa.fbbfae3cd0bp+124);
Examples:
auto a = cast(double) BigIntView!size_t.fromHexString!(char, true)("-afbb_fae3_cd0a_ff27_14a1_de70_22b0_029d");
assert(a == -0xa.fbbfae3cd0bp+124);
Examples:
auto a = cast(double) BigIntView!size_t.fromBinaryString!(char, true)("-1010_1111_1011_1011_1111_1010_1110_0011_1100_1101_0000_1010_1111_1111_0010_0111_0001_0100_1010_0001_1101_1110_0111_0000_0010_0010_1011_0000_0000_0010_1001_1101");
assert(a == -0xa.fbbfae3cd0bp+124);
const scope T opCast(T, bool nonZero = false)()
if (is(T == long) || is(T == int));
Examples:
auto view = BigIntView!size_t.fromHexString("-afbbfae3cd0aff2714a1de7022b0021d");
assert(cast(long) view == -0x14a1de7022b0021d);
assert(cast(int) view == -0x22b0021d);
Examples:
auto view = BigIntView!size_t.fromHexString!(char, true)("-afbb_fae3_cd0a_ff27_14a1_de70_22b0_021d");
assert(cast(long) view == -0x14a1de7022b0021d);
assert(cast(int) view == -0x22b0021d);
const scope T opCast(T : Fp!coefficientSize, size_t internalRoundLastBits = 0, bool wordNormalized = false, bool nonZero = false, size_t coefficientSize)()
if (internalRoundLastBits < size_t.sizeof * 8 && (size_t.sizeof >= W.sizeof || endian == TargetEndian));
Examples:
import mir.bignum.fixed: UInt;
import mir.bignum.fp: Fp;

auto fp = cast(Fp!128) BigIntView!size_t.fromHexString("-afbbfae3cd0aff2714a1de7022b0029d");
assert(fp.sign);
assert(fp.exponent == 0);
assert(fp.coefficient == UInt!128.fromHexString("afbbfae3cd0aff2714a1de7022b0029d"));
scope BigIntView!V opCast(T : BigIntView!V, V)() return
if (V.sizeof <= W.sizeof);
const pure nothrow @nogc @property scope @safe BigIntView!(const(W), endian) lightConst()() return;
const pure nothrow @nogc scope @safe sizediff_t opCmp(BigIntView!(const(W), endian) rhs);
const pure nothrow @nogc scope @safe bool opEquals(BigIntView!(const(W), endian) rhs);
const pure nothrow @nogc scope @safe bool opEquals(long rhs);
Returns:
true if the integer and equals to rhs.
BigIntView topMostSignificantPart(size_t length);
BigIntView topLeastSignificantPart(size_t length);
pure nothrow @nogc @safe bool opOpAssign(string op)(scope BigIntView!(const(W), endian) rhs, bool overflow = false)
if (op == "+" || op == "-");

pure nothrow @nogc @safe bool opOpAssign(string op)(scope BigUIntView!(const(W), endian) rhs, bool overflow = false)
if (op == "+" || op == "-");
Performs bool overflow = big +(-)= big operatrion.
Parameters:
BigIntView!(const(W), endian) rhs value to add with non-empty coefficients
bool overflow (overflow) initial iteration overflow

Precondition non-empty coefficients length of greater or equal to the rhs coefficients length.

Returns:
true in case of unsigned overflow
pure nothrow @nogc @safe bool opOpAssign(string op, T)(const T rhs)
if ((op == "+" || op == "-") && is(T == Signed!W));

pure nothrow @nogc @safe bool opOpAssign(string op, T)(const T rhs)
if ((op == "+" || op == "-") && is(T == W));
Performs bool overflow = big +(-)= scalar operatrion.

Precondition non-empty coefficients

Parameters:
T rhs value to add
Returns:
true in case of unsigned overflow
pure nothrow @nogc @safe W opOpAssign(string op : "*")(W rhs, W overflow = 0u);
Performs W overflow = (big += overflow) *= scalar operatrion.

Precondition non-empty coefficients

Parameters:
W rhs unsigned value to multiply by
W overflow initial overflow
Returns:
unsigned overflow value
BigIntView opUnary(string op : "-")();
Returns:
the same intger view with inversed sign
pure nothrow @nogc @property @safe auto leastSignificantFirst();
Returns:
a slice of coefficients starting from the least significant.
pure nothrow @nogc @property @safe auto mostSignificantFirst();
Returns:
a slice of coefficients starting from the most significant.
BigIntView normalized();

const BigIntView!(const(W), endian) normalized();
Strips zero most significant coefficients. Strips most significant zero coefficients. Sets sign to zero if no coefficients were left.
struct BigUIntAccumulator(W, WordEndian endian = TargetEndian) if (is(Unqual!W == uint) || is(Unqual!W == ulong));
An utility type to wrap a local buffer to accumulate unsigned numbers.
Examples:
import std.traits;
alias AliasSeq(T...) = T;

foreach (T; AliasSeq!(uint, ulong))
foreach (endian; AliasSeq!(WordEndian.little, WordEndian.big))
{
    T[16 / T.sizeof] buffer;
    auto accumulator = BigUIntAccumulator!(T, endian)(buffer);
    assert(accumulator.length == 0);
    assert(accumulator.coefficients.length == buffer.length);
    assert(accumulator.view.coefficients.length == 0);
    // needs to put a number before any operations on `.view`
    accumulator.put(1);
    // compute N factorial
    auto N = 30;
    foreach(i; 1 .. N + 1)
    {
        if (auto overflow = accumulator.view *= i)
        {
            if (!accumulator.canPut)
                throw new Exception("Factorial buffer overflow");
            accumulator.put(overflow);
        }
    }
    assert(accumulator.view == BigUIntView!(T, endian).fromHexString("D13F6370F96865DF5DD54000000"));
}
Examples:
Computes 13 * 10^^60
uint[7] buffer;
auto accumulator = BigUIntAccumulator!uint(buffer);
accumulator.put(13); // initial value
assert(accumulator.approxCanMulPow5(60));
accumulator.mulPow5(60);
assert(accumulator.canMulPow2(60));
accumulator.mulPow2(60);
assert(accumulator.view == BigUIntView!uint.fromHexString("81704fcef32d3bd8117effd5c4389285b05d000000000000000"));
W[] coefficients;
A group of coefficients for a DecimalRadix.!W.
The order corresponds to endianness.
The unused part can be uninitialized.
size_t length;
Current length of initialized coefficients.
The initialization order corresponds to endianness.
The view method may return a view with empty coefficients, which isn't usable. Put 0 or another number first to make the accumulator maintain a non-empty view.
pure nothrow @nogc @property @safe BigUIntView!(W, endian) view();
Returns:
Current unsigned integer view.

Note The method may return a view with empty coefficients, which isn't usable. Put 0 or another number first to make the accumulator maintain a non-empty view.

@property bool canPut();
Returns:
True if the accumulator can accept next most significant coefficient
void put(W coeffecient);
Places coefficient to the next most significant position.
void normalize();
Strips most significant zero coefficients from the current view.

Note The view method may return a view with empty coefficients, which isn't usable. Put 0 or another number first to make the accumulator maintain a non-empty view.

bool canPutN(size_t n);
bool approxCanMulPow5(size_t degree);
bool canMulPow2(size_t degree);
void mulPow5(size_t degree);
scope @safe void mulPow2(size_t degree);
enum DecimalExponentKey: int;
none
infinity
nan
dot
d
e
D
E
struct DecimalView(W, WordEndian endian = TargetEndian, Exp = sizediff_t) if (isUnsigned!W);
bool sign;
Exp exponent;
BigUIntView!(W, endian) coefficient;
pure nothrow @nogc scope @trusted bool fromStringImpl(C, bool allowSpecialValues = true, bool allowDotOnBounds = true, bool allowDExponent = true, bool allowStartingPlus = true, bool allowUnderscores = true, bool allowLeadingZeros = true, bool allowExponent = true, bool checkEmpty = true)(scope const(C)[] str, out DecimalExponentKey key, int exponentShift = 0)
if (isSomeChar!C);
Returns:
false in case of overflow or incorrect string.

Precondition non-empty coefficients

const pure nothrow @nogc @property @safe DecimalView!(const(W), endian, Exp) lightConst()();
BigIntView!(W, endian) signedCoefficient();
const scope T opCast(T, bool wordNormalized = false, bool nonZero = false)()
if (isFloatingPoint!T && isMutable!T);
Mir parsing supports up-to quadruple precision. The conversion error is 0 ULP for normal numbers. Subnormal numbers with an exponent greater than or equal to -512 have upper error bound equal to 1 ULP.
struct BinaryView(W, WordEndian endian = TargetEndian, Exp = int);
bool sign;
Exp exponent;
BigUIntView!(W, endian) coefficient;
const pure nothrow @nogc @property @safe DecimalView!(const(W), endian, Exp) lightConst()();
BigIntView!(W, endian) signedCoefficient();