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.

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) if (__traits(isUnsigned, W));
Arbitrary length unsigned integer view.
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");
Examples:
import mir.test;
auto view = BigUIntView!size_t.fromHexString!(char, true)("abcd_efab_cdef");
(cast(ulong)view).should == 0xabcd_efab_cdef;
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"));
Examples:
auto a = BigUIntView!size_t.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
a.smallRightShiftInPlace(4);
assert(a == BigUIntView!size_t.fromHexString("afbbfae3cd0aff2714a1de7022b0029"));
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__");
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__");
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);
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!size_t.fromHexString("ae3cd0aff2714a1de7022b0029d");
assert(fp.exponent == -20);
assert(fp.coefficient == UInt!128.fromHexString("ae3cd0aff2714a1de7022b0029d00000"));

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("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"));
Examples:
auto view = BigUIntView!ulong.fromHexString("afbbfae3cd0aff2714a1de7022b0029d");
assert(cast(ulong) view == 0x14a1de7022b0029d);
assert(cast(uint) view == 0x22b0029d);
assert(cast(ubyte) view == 0x9d);
Examples:
import std.traits;
alias AliasSeq(T...) = T;

foreach (T; AliasSeq!(ubyte, ushort, uint, ulong))
{
    T[3] lhsData = [1, T.max-1, 0];
    T[3] rhsData = [T.max, T.max, 0];

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

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

        ///  bool overflow = bigUInt op= bigUInt/bigInt
        lhs = BigUIntView!T(lhsData);
        auto rhs = BigUIntView!T(rhsData).normalized;
        assert(lhs.coefficients == [Signed!T.max + 2, 0, 0]);
        assert(rhs.coefficients == [T.max, T.max]);
        assert((lhs += rhs) == false);
        assert(lhs.coefficients == [Signed!T.max + 1, 0, 1]);
        assert((lhs -= rhs) == false);
        assert(lhs.coefficients == [Signed!T.max + 2, 0, 0]);
        assert((lhs += -rhs) == true);
        assert(lhs.coefficients == [Signed!T.max + 3, 0, T.max]);
        assert((lhs += -(-rhs)) == true);
        assert(lhs.coefficients == [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.coefficients == [0, Signed!T.max + 2, 0]);
        lhs = lhs.normalized;
        lhs.coefficients[1] = T.max / 2 + 3;
        assert(lhs.coefficients == [0, T.max / 2 + 3]);
        assert((lhs *= 8u) == 4);
        assert(lhs.coefficients == [0, 16]);
    }
}
W[] coefficients;
A group of coefficients for a radix W.max + 1.
The order corresponds to endianness.
const pure nothrow @nogc @property @safe size_t length()();

Retrurns signed integer view using the same data payload

pure nothrow @nogc @property @safe BigIntView!W signed()(bool sign = false) return scope;

Retrurns signed integer view using the same data payload

const T opCast(T)() scope
if (isFloatingPoint!T && isMutable!T);
const @safe T opCast(T : Fp!coefficientSize, uint coefficientSize)() scope;
const T opCast(T, bool nonZero = false)() scope
if (isIntegral!T && isUnsigned!T && isMutable!T);
pure nothrow @nogc BigUIntView!V opCast(T : BigUIntView!V, V)() return scope
if (V.sizeof <= W.sizeof);
const pure nothrow @nogc @property @safe BigUIntView!(const(W)) lightConst()() return scope;
const pure nothrow @nogc @safe sizediff_t opCmp(scope BigUIntView!(const(W)) rhs) scope;
const pure nothrow @nogc @safe bool opEquals(BigUIntView!(const(W)) rhs) scope;
void popMostSignificant() scope;
void popLeastSignificant() scope;
BigUIntView topMostSignificantPart(size_t length);
BigUIntView topLeastSignificantPart(size_t length);
void smallLeftShiftInPlace()(uint shift) scope;
Shifts left using at most size_t.sizeof * 8 - 1 bits
void smallRightShiftInPlace()(uint shift);
Shifts right using at most size_t.sizeof * 8 - 1 bits
pure @trusted BigUIntView 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) scope
if (isSomeChar!C);
pure @trusted BigUIntView 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) scope
if (isSomeChar!C);
pure nothrow @nogc @trusted bool fromStringImpl(C)(scope const(C)[] str) scope
if (isSomeChar!C);
Returns:
false in case of overflow or incorrect string.

Precondition non-empty coefficients

Note doesn't support signs.

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

pure nothrow @nogc @safe bool opOpAssign(string op)(scope BigIntView!(const(W)) rhs, bool overflow = false) scope
if (op == "+" || op == "-");
Performs bool overflow = big +(-)= big operatrion.
Parameters:
BigUIntView!(const(W)) 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) scope
if ((op == "+" || op == "-") && is(T == W));

pure nothrow @nogc @safe bool opOpAssign(string op, T)(const T rhs) scope
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 @safe W opOpAssign(string op : "*")(W rhs, W overflow = 0u) scope;
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 @safe uint opOpAssign(string op : "/")(uint rhs, uint overflow = 0) scope;
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 @safe UInt!size opOpAssign(string op : "*", size_t size)(UInt!size rhs, UInt!size overflow = 0) scope;
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
BigIntView!W opUnary(string op : "-")();
Returns:
the same intger view with inversed sign
void bitwiseNotInPlace() scope;
bool twoComplementInPlace() scope;
Performs number=-number operatrion.

Precondition non-empty coefficients

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

const BigUIntView!(const(W)) normalized() return scope;
Strips most significant zero coefficients.
bool bt()(size_t position) scope;
const pure nothrow @nogc @property @safe size_t ctlz()() scope;
const pure nothrow @nogc @property @safe size_t cttz()() scope;
BigIntView!W withSign()(bool sign) return scope;
const pure nothrow @nogc @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 @safe bool opEquals(ulong rhs) scope;
Returns:
true if the integer and equals to rhs.
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
struct BigIntView(W) if (is(Unqual!W == ubyte) || is(Unqual!W == ushort) || is(Unqual!W == uint) || is(Unqual!W == ulong));
Arbitrary length signed integer view.
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"));
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);
Examples:
import std.traits;
alias AliasSeq(T...) = T;

foreach (T; AliasSeq!(ubyte, ushort, uint, ulong))
{
    T[3] lhsData = [1, T.max-1, 0];
    T[3] rhsData = [T.max, T.max, 0];

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

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

    static if (T.sizeof >= 4)
    {

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

        ///  bool overflow = bigUInt op= bigUInt/bigInt
        lhs = BigIntView!T(lhsData);
        auto rhs = BigUIntView!T(rhsData).normalized;
        assert(lhs.coefficients == [Signed!T.max + 2, 0, 0]);
        assert(rhs.coefficients == [T.max, T.max]);
        assert((lhs += rhs) == false);
        assert(lhs.coefficients == [Signed!T.max + 1, 0, 1]);
        assert((lhs -= rhs) == false);
        assert(lhs.coefficients == [Signed!T.max + 2, 0, 0]);
        assert((lhs += -rhs) == false);
        assert(lhs.sign);
        assert(lhs.coefficients == [T.max - (Signed!T.max + 2), T.max, 0]);
        assert(lhs.sign);
        assert((lhs -= -rhs) == false);
        assert(lhs.coefficients == [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 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 inout(W)[] coefficients();
this(W[] coefficients, bool sign = false);
this(BigUIntView!W unsigned, bool sign = false);
pure nothrow @nogc @trusted bool fromStringImpl(C)(scope const(C)[] str) scope
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 T opCast(T)() scope
if (isFloatingPoint!T && isMutable!T);
const T opCast(T, bool nonZero = false)() scope
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 T opCast(T : Fp!coefficientSize, uint coefficientSize)() scope;
BigIntView!V opCast(T : BigIntView!V, V)() return scope
if (V.sizeof <= W.sizeof);
const BigIntView!V opCast(T : BigIntView!V, V)() return scope
if (V.sizeof <= W.sizeof);
const pure nothrow @nogc @property @safe BigIntView!(const(W)) lightConst()() return scope;
const pure nothrow @nogc @safe sizediff_t opCmp(BigIntView!(const(W)) rhs) scope;
const pure nothrow @nogc @safe bool opEquals(BigIntView!(const(W)) rhs) scope;
const pure nothrow @nogc @safe bool opEquals(long rhs) scope;
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)) rhs, bool overflow = false)
if (op == "+" || op == "-");

pure nothrow @nogc @safe bool opOpAssign(string op)(scope BigUIntView!(const(W)) rhs, bool overflow = false)
if (op == "+" || op == "-");
Performs bool overflow = big +(-)= big operatrion.
Parameters:
BigIntView!(const(W)) 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 coefficients();
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() return scope;

const BigIntView!(const(W)) normalized() return scope;
Strips zero most significant coefficients. Strips most significant zero coefficients. Sets sign to zero if no coefficients were left.
struct DecimalView(W) if (is(Unqual!W == size_t));
Examples:
{
    auto view = DecimalView!ulong(false, -8, BigUIntView!ulong.fromHexString("BEBC2000000011E1A3"));
    auto coeff = (cast(BigUIntView!uint)view.coefficient).lightConst;
    assert (algoM!double(0.0, coeff, cast(int)view.exponent) == 3.518437208883201171875E+013);
}

// TBD: triggers underflow
// {
//     auto view = DecimalView!ulong(false, 0, BigUIntView!ulong.fromHexString("88BF4748507FB9900ADB624CCFF8D78897DC900FB0460327D4D86D327219"));
//     auto coeff = (cast(BigUIntView!uint)view.coefficient).lightConst;
//     debug {
//         import std.stdio;
//         writefln("%s", algoM!float(0.0, coeff, cast(int)view.exponent));
//         writefln("%s", algoM!double(0.0, coeff, cast(int)view.exponent));
//     }
//     assert (algoM!float(0.0, coeff, cast(int)view.exponent) == float.infinity);
//     assert (algoM!double(0.0, coeff, cast(int)view.exponent) == 0x1.117e8e90a0ff7p+239);
// }

{
    auto view = DecimalView!ulong(false, -324, BigUIntView!ulong.fromHexString("4F0CEDC95A718E"));
    auto coeff = (cast(BigUIntView!uint)view.coefficient).lightConst;
    assert (algoM!float(0.0, coeff, cast(int)view.exponent) == 0);
    assert (algoM!double(0.0, coeff, cast(int)view.exponent) == 2.2250738585072014e-308);
}
Examples:
import mir.test;

auto view = DecimalView!size_t(false, -8, BigUIntView!size_t.fromHexString("BEBC2000000011E1A3"));

should(cast(float)view) == 3.518437208883201171875E+013f;
should(cast(double)view) == 3.518437208883201171875E+013;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 3.518437208883201171875E+013L;

view = DecimalView!size_t(true, -169, BigUIntView!size_t.fromHexString("5A174AEDA65CC"));
should(cast(float)view) == -0;
should(cast(double)view) == -0x1.1p-511;
static if (real.mant_dig >= 64)
    should(cast(real)view) == -0x8.80000000000019fp-514L;

view = DecimalView!size_t(true, 293, BigUIntView!size_t.fromHexString("36496F6C4ED38"));
should(cast(float)view) == -float.infinity;
should(cast(double)view) == -9.55024478104888e+307;
static if (real.mant_dig >= 64)
    should(cast(real)view) == -9.55024478104888e+307L;

view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 1;
should(cast(double)view) == 1;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 1L;

view = DecimalView!size_t(false, -5, BigUIntView!size_t.fromHexString("3"));
should(cast(float)view) == 3e-5f;
should(cast(double)view) == 3e-5;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 3e-5L;

view = DecimalView!size_t(false, -1, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0.1f;
should(cast(double)view) == 0.1;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0.1L;

view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("3039"));
should(cast(float)view) == 12345.0f;
should(cast(double)view) == 12345.0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 12345.0L;

view = DecimalView!size_t(false, -7, BigUIntView!size_t.fromHexString("98967F"));
should(cast(float)view) == 0.9999999f;
should(cast(double)view) == 0.9999999;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0.9999999L;

view = DecimalView!size_t(false, -324, BigUIntView!size_t.fromHexString("4F0CEDC95A718E"));
should(cast(float)view) == 0;
should(cast(double)view) == 2.2250738585072014e-308;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 2.2250738585072014e-308L;

view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("1FFFFFFFFFFFFFFFD"));
should(cast(float)view) == 36893488147419103229f;
should(cast(double)view) == 36893488147419103229.0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x1FFFFFFFFFFFFFFFDp0L;

view = DecimalView!size_t(false, -33, BigUIntView!size_t.fromHexString("65"));
should(cast(float)view) == 101e-33f;
should(cast(double)view) == 101e-33;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 101e-33L;

view = DecimalView!size_t(false, 23, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 1e23f;
should(cast(double)view) == 1e23;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 1e23L;

view = DecimalView!size_t(false, 23, BigUIntView!size_t.fromHexString("81B"));
should(cast(float)view) == 2075e23f;
should(cast(double)view) == 0xaba3d58a1f1a98p+32;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xaba3d58a1f1a9cp+32L;

view = DecimalView!size_t(false, -23, BigUIntView!size_t.fromHexString("2209"));
should(cast(float)view) == 8713e-23f;
should(cast(double)view) == 0x1.9b75b4e7de2b9p-64;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xc.dbada73ef15c401p-67L;

view = DecimalView!size_t(false, 300, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == 0x1.7e43c8800759cp+996;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xb.f21e44003acdd2dp+993L;

view = DecimalView!size_t(false, 245, BigUIntView!size_t.fromHexString("B3A73CEB227"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == 0x1.48e3735333cb6p+857;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xa.471b9a999e5b01ep+854L;

view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("88BF4748507FB9900ADB624CCFF8D78897DC900FB0460327D4D86D327219"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == 0x1.117e8e90a0ff7p+239;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.8bf4748507fb99p+236L;

view = DecimalView!size_t(false, -324, BigUIntView!size_t.fromHexString("5"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x0.0000000000001p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.18995ce7aa0e1b2p-1077L;

view = DecimalView!size_t(false, -324, BigUIntView!size_t.fromHexString("5B"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x0.0000000000012p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x9.3594d9adeb09a55p-1073L;

view = DecimalView!size_t(false, -322, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x0.0000000000014p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xa.1ebfb4219491a1fp-1073L;

view = DecimalView!size_t(false, -320, BigUIntView!size_t.fromHexString("CA1CCB"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x0.000063df832d9p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xc.7bf065b215888c7p-1043L;

view = DecimalView!size_t(false, -319, BigUIntView!size_t.fromHexString("33CE7943FB"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x1.000000000162p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.000000000b103b6p-1025L;

view = DecimalView!size_t(false, -309, BigUIntView!size_t.fromHexString("15"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x0.f19c2629ccf53p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xf.19c2629ccf52fc4p-1026L;

view = DecimalView!size_t(false, -340, BigUIntView!size_t.fromHexString("AF87023B9BF0EE"));
should(cast(float)view) == 0;
should(cast(double)view) == 0x0.0000000000001p-1022;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xf.fffffffffffff64p-1078L;

view = DecimalView!size_t(false, 400, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == double.infinity;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xd.a763fc8cb9ff9e6p+1325L;

view = DecimalView!size_t(false, 309, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == double.infinity;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xb.201833b35d63f73p+1023L;

view = DecimalView!size_t(false, 308, BigUIntView!size_t.fromHexString("2"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == double.infinity;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.e679c2f5e44ff8fp+1021L;

view = DecimalView!size_t(false, 308, BigUIntView!size_t.fromHexString("2"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == double.infinity;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.e679c2f5e44ff8fp+1021L;

view = DecimalView!size_t(false, 295, BigUIntView!size_t.fromHexString("1059949B7090"));
should(cast(float)view) == float.infinity;
should(cast(double)view) == double.infinity;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.00000000006955ap+1021L;

view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("0"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0L;

view = view;
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0L;

view = DecimalView!size_t(false, -325, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xa.5ced43b7e3e9188p-1083L;

view = DecimalView!size_t(false, -326, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.4a57695fe98746dp-1086L;

view = DecimalView!size_t(false, -500, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.33ada2003db9a8p-1664L;

view = DecimalView!size_t(false, -1000, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.68a9188a89e1467p-3325L;

view = DecimalView!size_t(false, -4999, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0L;

view = DecimalView!size_t(false, -10000, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0L;

view = DecimalView!size_t(false, -4969, BigUIntView!size_t.fromHexString("329659A941466C6B"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == real.min_normal * real.epsilon;

view = DecimalView!size_t(false, -15, BigUIntView!size_t.fromHexString("525DB0200FFAB"));
should(cast(float)view) == 1.448997445238699f;
should(cast(double)view) == 0x1.72f17f1f49aadp+0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xb.978bf8fa4d56cp-3L;

view = DecimalView!size_t(false, -15, BigUIntView!size_t.fromHexString("525DB0200FFAB"));
should(cast(float)view) == 1.448997445238699f;
should(cast(double)view) == 0x1.72f17f1f49aadp+0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xb.978bf8fa4d56cp-3L;

view = DecimalView!size_t(false, -325, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xa.5ced43b7e3e9188p-1083L;

view = DecimalView!size_t(false, -326, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0;
should(cast(double)view) == 0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8.4a57695fe98746dp-1086L;

view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 1;
should(cast(double)view) == 0x1p+0;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0x8p-3L;

view = DecimalView!size_t(false, -5, BigUIntView!size_t.fromHexString("3"));
should(cast(float)view) == 3e-5f;
should(cast(double)view) == 0x1.f75104d551d69p-16;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xf.ba8826aa8eb4635p-19L;

view = DecimalView!size_t(false, -1, BigUIntView!size_t.fromHexString("1"));
should(cast(float)view) == 0.1f;
should(cast(double)view) == 0x1.999999999999ap-4;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xc.ccccccccccccccdp-7L;

view = DecimalView!size_t(false, -7, BigUIntView!size_t.fromHexString("98967F"));
should(cast(float)view) == 0.9999999f;
should(cast(double)view) == 0x1.fffffca501acbp-1;
static if (real.mant_dig >= 64)
    should(cast(real)view) == 0xf.ffffe5280d65435p-4L;
bool sign;
long exponent;
BigUIntView!W coefficient;
pure nothrow @nogc @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) scope
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)) lightConst()() return scope;
BigIntView!W signedCoefficient();
const T opCast(T, bool wordNormalized = false)() scope
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);
bool sign;
long exponent;
BigUIntView!W coefficient;
const pure nothrow @nogc @property @safe DecimalView!(const(W)) lightConst()() return scope;
BigIntView!W signedCoefficient();