Strips most significant zero coefficients from the current view. Note: The view method may return a view with empty coefficients, which isn't usable. Put 0 or another number first to make the accumulator maintain a non-empty view.
Places coefficient to the next most significant position.
A group of coefficients for a DecimalRadix!W.
Current length of initialized coefficients.
import std.traits; alias AliasSeq(T...) = T; foreach (T; AliasSeq!(uint, ulong)) foreach (endian; AliasSeq!(WordEndian.little, WordEndian.big)) { T[16 / T.sizeof] buffer; auto accumulator = BigUIntAccumulator!(T, endian)(buffer); assert(accumulator.length == 0); assert(accumulator.coefficients.length == buffer.length); assert(accumulator.view.coefficients.length == 0); // needs to put a number before any operations on `.view` accumulator.put(1); // compute N factorial auto N = 30; foreach(i; 1 .. N + 1) { if (auto overflow = accumulator.view *= i) { if (!accumulator.canPut) throw new Exception("Factorial buffer overflow"); accumulator.put(overflow); } } assert(accumulator.view == BigUIntView!(T, endian).fromHexString("D13F6370F96865DF5DD54000000")); }
Computes 13 * 10^^60
uint[7] buffer; auto accumulator = BigUIntAccumulator!uint(buffer); accumulator.put(13); // initial value assert(accumulator.approxCanMulPow5(60)); accumulator.mulPow5(60); assert(accumulator.canMulPow2(60)); accumulator.mulPow2(60); assert(accumulator.view == BigUIntView!uint.fromHexString("81704fcef32d3bd8117effd5c4389285b05d000000000000000"));
An utility type to wrap a local buffer to accumulate unsigned numbers.