The OpenD Programming Language

BigIntView

Arbitrary length signed integer view.

Constructors

this
this(W[] coefficients, bool sign)
this
this(BigUIntView!W unsigned, bool sign)

Alias This

lightConst

ditto

Members

Functions

coefficients
inout(W)[] coefficients()
coefficients
auto coefficients()
fromBinaryStringImpl
bool fromBinaryStringImpl(const(C)[] str)
fromHexStringImpl
bool fromHexStringImpl(const(C)[] str)
fromStringImpl
bool fromStringImpl(const(C)[] str)
lightConst
BigIntView!(const W) lightConst()
mostSignificantFirst
auto mostSignificantFirst()
normalized
BigIntView normalized()
BigIntView!(const W) normalized()

Strips zero most significant coefficients. Strips most significant zero coefficients. Sets sign to zero if no coefficients were left.

opCast
T opCast()
opCast
T opCast()
opCast
T opCast()
opCast
BigIntView!V opCast()
opCast
BigIntView!V opCast()
opCmp
sizediff_t opCmp(BigIntView!(const W) rhs)
opEquals
bool opEquals(BigIntView!(const W) rhs)
opEquals
bool opEquals(long rhs)
opOpAssign
bool opOpAssign(BigIntView!(const W) rhs, bool overflow)
bool opOpAssign(BigUIntView!(const W) rhs, bool overflow)

Performs bool overflow = big +(-)= big operatrion.

opOpAssign
bool opOpAssign(T rhs)

Performs bool overflow = big +(-)= scalar operatrion. Precondition: non-empty coefficients

opOpAssign
W opOpAssign(W rhs, W overflow)

Performs W overflow = (big += overflow) *= scalar operatrion. Precondition: non-empty coefficients

opUnary
BigIntView opUnary()
topLeastSignificantPart
BigIntView topLeastSignificantPart(size_t length)
topMostSignificantPart
BigIntView topMostSignificantPart(size_t length)

Static functions

fromBinaryString
BigIntView fromBinaryString(const(C)[] str)
fromHexString
BigIntView fromHexString(const(C)[] str)

Variables

sign
bool sign;

Sign bit

unsigned
BigUIntView!W unsigned;

Self-assigned to unsigned integer view BigUIntView.

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"));
auto a = cast(double) BigIntView!size_t.fromHexString("-afbbfae3cd0aff2714a1de7022b0029d");
assert(a == -0xa.fbbfae3cd0bp+124);
auto a = cast(double) BigIntView!size_t.fromBinaryString("-10101111101110111111101011100011110011010000101011111111001001110001010010100001110111100111000000100010101100000000001010011101");
assert(a == -0xa.fbbfae3cd0bp+124);
auto a = cast(double) BigIntView!size_t.fromHexString!(char, true)("-afbb_fae3_cd0a_ff27_14a1_de70_22b0_029d");
assert(a == -0xa.fbbfae3cd0bp+124);
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);
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);
    }
}
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"));
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"));

Meta