ditto
Strips most significant zero coefficients.
Performs bool overflow = big +(-)= big operatrion.
Performs bool Overflow = big +(-)= scalar operatrion. Precondition: non-empty coefficients
Performs W overflow = (big += overflow) *= scalar operatrion. Precondition: non-empty coefficients
Performs uint remainder = (overflow$big) /= scalar operatrion, where $ denotes big-endian concatenation. Precondition: non-empty coefficients, overflow < rhs
Performs W overflow = (big += overflow) *= scalar operatrion. Precondition: non-empty coefficients
Retrurns: signed integer view using the same data payload
Shifts left using at most size_t.sizeof * 8 - 1 bits
Shifts right using at most size_t.sizeof * 8 - 1 bits
Performs number=-number operatrion. Precondition: non-empty coefficients
A group of coefficients for a radix W.max + 1.
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 }
Arbitrary length unsigned integer view.