BigUIntView

Arbitrary length unsigned integer view.

struct BigUIntView (
W
WordEndian endian = TargetEndian
) if (
__traits(isUnsigned, W)
) {}

Alias This

lightConst

ditto

Members

Functions

bitwiseNotInPlace
void bitwiseNotInPlace()
bt
bool bt(size_t position)
ctlz
size_t ctlz()
cttz
size_t cttz()
fromHexStringImpl
bool fromHexStringImpl(const(C)[] str)
fromStringImpl
bool fromStringImpl(const(C)[] str)
get
bool get(U value)
leastSignificant
inout(W) leastSignificant()
leastSignificantFirst
auto leastSignificantFirst()
leastSignificantFirst
auto leastSignificantFirst()
lightConst
BigUIntView!(const W, endian) lightConst()
mostSignificant
inout(W) mostSignificant()
mostSignificantFirst
auto mostSignificantFirst()
mostSignificantFirst
auto mostSignificantFirst()
normalized
BigUIntView normalized()
BigUIntView!(const W, endian) normalized()

Strips most significant zero coefficients.

opCast
T opCast()
opCast
T opCast()
opCast
T opCast()
opCast
BigUIntView!V opCast()
opCmp
sizediff_t opCmp(BigUIntView!(const W, endian) rhs)
opEquals
bool opEquals(BigUIntView!(const W, endian) rhs)
opEquals
bool opEquals(ulong rhs)
opOpAssign
bool opOpAssign(BigUIntView!(const W, endian) rhs, bool overflow)
bool opOpAssign(BigIntView!(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

opOpAssign
uint opOpAssign(uint rhs, uint overflow)

Performs uint remainder = (overflow$big) /= scalar operatrion, where $ denotes big-endian concatenation. Precondition: non-empty coefficients, overflow < rhs

opOpAssign
UInt!size opOpAssign(UInt!size rhs, UInt!size overflow)

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

opUnary
BigIntView!(W, endian) opUnary()
popLeastSignificant
void popLeastSignificant()
popMostSignificant
void popMostSignificant()
signed
BigIntView!(W, endian) signed()

Retrurns: signed integer view using the same data payload

smallLeftShiftInPlace
void smallLeftShiftInPlace(uint shift)

Shifts left using at most size_t.sizeof * 8 - 1 bits

smallRightShiftInPlace
void smallRightShiftInPlace(uint shift)

Shifts right using at most size_t.sizeof * 8 - 1 bits

toStringImpl
size_t toStringImpl(C[] str)
topLeastSignificantPart
BigUIntView topLeastSignificantPart(size_t length)
topMostSignificantPart
BigUIntView topMostSignificantPart(size_t length)
twoComplementInPlace
bool twoComplementInPlace()

Performs number=-number operatrion. Precondition: non-empty coefficients

withSign
BigIntView!(W, endian) withSign(bool sign)

Static functions

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

Variables

coefficients
W[] coefficients;

A group of coefficients for a radix W.max + 1.

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 = BigUIntView!(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     static if (T.sizeof >= 4)
24     {
25         assert((lhs += T.max) == false);
26         assert(lhs.leastSignificantFirst == [0, T.max]);
27         assert((lhs += T.max) == false);
28         assert((lhs += T.max) == true); // overflow bit
29         assert(lhs.leastSignificantFirst == [T.max-1, 0]);
30         assert((lhs -= T(1)) == false);
31         assert(lhs.leastSignificantFirst == [T.max-2, 0]);
32         assert((lhs -= T.max) == true); // underflow bit
33         assert(lhs.leastSignificantFirst == [T.max-1, T.max]);
34         assert((lhs -= Signed!T(-4)) == true); // overflow bit
35         assert(lhs.leastSignificantFirst == [2, 0]);
36         assert((lhs += Signed!T.max) == false); // overflow bit
37         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0]);
38 
39         ///  bool overflow = bigUInt op= bigUInt/bigInt
40         lhs = BigUIntView!(T, endian)(lhsData);
41         auto rhs = BigUIntView!(T, endian)(rhsData).normalized;
42         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
43         assert(rhs.leastSignificantFirst == [T.max, T.max]);
44         assert((lhs += rhs) == false);
45         assert(lhs.leastSignificantFirst == [Signed!T.max + 1, 0, 1]);
46         assert((lhs -= rhs) == false);
47         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
48         assert((lhs += -rhs) == true);
49         assert(lhs.leastSignificantFirst == [Signed!T.max + 3, 0, T.max]);
50         assert((lhs += -(-rhs)) == true);
51         assert(lhs.leastSignificantFirst == [Signed!T.max + 2, 0, 0]);
52 
53         /// W overflow = bigUInt *= scalar
54         assert((lhs *= T.max) == 0);
55         assert((lhs += T(Signed!T.max + 2)) == false);
56         assert(lhs.leastSignificantFirst == [0, Signed!T.max + 2, 0]);
57         lhs = lhs.normalized;
58         lhs.leastSignificantFirst[1] = T.max / 2 + 3;
59         assert(lhs.leastSignificantFirst == [0, T.max / 2 + 3]);
60         assert((lhs *= 8u) == 4);
61         assert(lhs.leastSignificantFirst == [0, 16]);
62     }
63 }

Meta