gfm

Provide a 2^N-bit integer type. Guaranteed to never allocate and expected binary layout Recursive implementation with very slow division.

Supports all operations that builtin integers support.

Known Bugs
it's not sure if the unsigned operand would take precedence in a comparison/division. - a < b should be an unsigned comparison if at least one operand is unsigned - a / b should be an unsigned division if at least one operand is unsigned

template  wideint(int bits)

Wide signed integer.

Parameters
bits number of bits, must be a power of 2.

template  uwideint(int bits)

Wide unsigned integer.

Parameters
bits number of bits, must be a power of 2.

struct  wideIntImpl(bool signed, int bits);

Recursive 2^n integer implementation.


pure nothrow @nogc this(T)(T x);

Construct from a value.


enum auto  literal(string digits);

Construct from compile-time digit string.

Both decimal and hex digit strings are supported.



Example:
auto x = int128.literal!"20_000_000_000_000_000_001";

assert((x >>> 1) == 0x8AC7_2304_89E8_0000);



auto y = int126.literal!"0x1_158E_4609_13D0_0001";

assert(y == x);


pure nothrow @nogc ref self  opAssign(T)(T n) if (isIntegral!T && isUnsigned!T);

Assign with a smaller unsigned type.


pure nothrow @nogc ref self  opAssign(T)(T n) if (isIntegral!T && isSigned!T);

Assign with a smaller signed type (sign is extended).


pure nothrow @nogc ref self  opAssign(T)(T n) if (isWideIntInstantiation!T && T._bits == bits);

Assign with a wide integer of the same size (sign is lost).


pure nothrow @nogc ref self  opAssign(T)(T n) if (isWideIntInstantiation!T && T._bits < bits);

Assign with a smaller wide integer (sign is extended accordingly).


const pure nothrow @nogc T  opCast(T)() if (isIntegral!T);

Cast to a smaller integer type (truncation).


const pure nothrow @nogc T  opCast(T)() if (is(T == bool));

Cast to bool.


const pure nothrow @nogc T  opCast(T)() if (isWideIntInstantiation!T);

Cast to wide integer of any size.


const void  toString(DG, Char)(DG sink, FormatSpec!Char fmt) if (is(typeof(sink((const(Char)[]).init))));

Converts to a string. Supports format specifiers %d, %s (both decimal)

and %x (hex).