BigIntView

Arbitrary length signed integer view.

Constructors

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

Alias This

lightConst

ditto

Members

Functions

coefficients
inout(W)[] coefficients()
fromHexStringImpl
bool fromHexStringImpl(const(C)[] str)
fromStringImpl
bool fromStringImpl(const(C)[] str)
leastSignificantFirst
auto leastSignificantFirst()
lightConst
BigIntView!(const W, endian) lightConst()
mostSignificantFirst
auto mostSignificantFirst()
normalized
BigIntView normalized()
BigIntView!(const W, endian) 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()
opCmp
sizediff_t opCmp(BigIntView!(const W, endian) rhs)
opEquals
bool opEquals(BigIntView!(const W, endian) rhs)
opEquals
bool opEquals(long rhs)
opOpAssign
bool opOpAssign(BigIntView!(const W, endian) rhs, bool overflow)
bool opOpAssign(BigUIntView!(const W, endian) 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

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

Variables

sign
bool sign;

Sign bit

unsigned
BigUIntView!(W, endian) unsigned;

Self-assigned to unsigned integer view BigUIntView.

Examples

1 import std.traits;
2 alias AliasSeq(T...) = T;
3 
4 foreach (T; AliasSeq!(ubyte, ushort, uint, ulong))
5 foreach (endian; AliasSeq!(WordEndian.little, WordEndian.big))
6 {
7     static if (endian == WordEndian.little)
8     {
9         T[3] lhsData = [1, T.max-1, 0];
10         T[3] rhsData = [T.max, T.max, 0];
11     }
12     else
13     {
14         T[3] lhsData = [0, T.max-1, 1];
15         T[3] rhsData = [0, T.max, T.max];
16     }
17 
18     auto lhs = BigIntView!(T, endian)(lhsData).normalized;
19 
20     ///  bool overflow = bigUInt op= scalar
21     assert(lhs.leastSignificantFirst == [1, T.max-1]);
22     assert(lhs.mostSignificantFirst == [T.max-1, 1]);
23 
24     static if (T.sizeof >= 4)
25     {
26 
27         assert((lhs += T.max) == false);
28         assert(lhs.leastSignificantFirst == [0, T.max]);
29         assert((lhs += T.max) == false);
30         assert((lhs += T.max) == true); // overflow bit
31         assert(lhs.leastSignificantFirst == [T.max-1, 0]);
32         assert((lhs -= T(1)) == false);
33         assert(lhs.leastSignificantFirst == [T.max-2, 0]);
34         assert((lhs -= T.max) == false);
35         assert(lhs.leastSignificantFirst == [2, 0]);
36         assert(lhs.sign);
37         assert((lhs -= Signed!T(-4)) == false);
38         assert(lhs.leastSignificantFirst == [2, 0]);
39         assert(lhs.sign == false);
40         assert((lhs += Signed!T.max) == false);
41         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0]);
42 
43         ///  bool overflow = bigUInt op= bigUInt/bigInt
44         lhs = BigIntView!(T, endian)(lhsData);
45         auto rhs = BigUIntView!(T, endian)(rhsData).normalized;
46         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
47         assert(rhs.leastSignificantFirst == [T.max, T.max]);
48         assert((lhs += rhs) == false);
49         assert(lhs.leastSignificantFirst == [Signed!T.max + 1, 0, 1]);
50         assert((lhs -= rhs) == false);
51         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
52         assert((lhs += -rhs) == false);
53         assert(lhs.sign);
54         assert(lhs.leastSignificantFirst == [T.max - (Signed!T.max + 2), T.max, 0]);
55         assert(lhs.sign);
56         assert((lhs -= -rhs) == false);
57         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
58         assert(lhs.sign == false);
59     }
60 }
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