WideUInt

Struct emulating a large (bigger than ulong) non-negative integer of fixed range (defined via template argument). ulong but still fixed in size (defined via template argument).

Such struct is a value type with stable binary layout for a given size which is the primary goal of this implementation. Performance may be eventually improved if necessity arises, right now implementation is intentionally simplistic and naive.

Internally wide integer is represented by a static array of uint values such that concatenating their binary representation together results in long binary sequence representing actual stored number.

Constructors

this
this(ulong value)

Constructor from a regular ulong

Members

Functions

decimal_digits
size_t decimal_digits()
divideBy
uint divideBy(uint rhs)

Mutates current number in-place, dividing it by rhs and calculating remainder.

multiplyBy
void multiplyBy(uint rhs)

Mutates this number in place multiplying it by a regular integer

opAssign
void opAssign(ulong rhs)

Enables assignment from a plain integer type

opCmp
int opCmp(typeof(this) rhs)

Enables ordering comparison with WideUInt of the same size

opEquals
equals_t opEquals(ulong rhs)

Enables equality comparison with a plain integer type

opEquals
equals_t opEquals(WideUInt rhs)

Enables equality comparison with WideUInt of the same size

opOpAssign
void opOpAssign(uint rhs)

Increment current value by one fitting in uint

toDouble
double toDouble()
toString
istring toString()

Inefficient allocating string conversion useful for tests and prototyping.

toString
void toString(void delegate(cstring) sink)

Sink based string conversion

Parameters

N

amount of uint-size words to use as a backing storage for the number

Examples

WideUInt!(4) counter;
counter = 10000000000000000000U;
counter.multiplyBy(10);
++counter;
test!("==")(counter.toString(), "100000000000000000001");

Meta