BigInt

Stack-allocated big signed integer.

Constructors

this
this(UInt!size fixedInt)
this
this(size_t[N] data)
this
this(ulong data)
this
this(const(char)[] str)

Members

Functions

copy
BigInt copy()
copyFrom
bool copyFrom(BigIntView!(const W, endian) view)
bool copyFrom(BigUIntView!(const W, endian) view)
fromHexStringImpl
bool fromHexStringImpl(const(C)[] str)
fromStringImpl
bool fromStringImpl(const(C)[] str)
mulPow5
bool mulPow5(size_t degree)
normalize
void normalize()
opAssign
ref opAssign(ulong data)
opAssign
ref opAssign(BigInt!rhsMaxSize64 rhs)
opCast
T opCast()
opCast
T opCast()
opCmp
auto opCmp(BigInt rhs)
opEquals
bool opEquals(BigInt rhs)
opEquals
bool opEquals(size_t rhs, bool rhsSign)
opEquals
bool opEquals(sizediff_t rhs)
opOpAssign
size_t opOpAssign(size_t rhs, size_t overflow)

Performs size_t overflow = (big += overflow) *= scalar operatrion.

opOpAssign
uint opOpAssign(uint rhs, uint overflow)

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

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

Performs size_t overflow = (big += overflow) *= fixed operatrion.

opOpAssign
bool opOpAssign(BigInt!rhsMaxSize64 rhs)
bool opOpAssign(BigIntView!(const size_t) rhs)

Performs size_t overflow = big *= fixed operatrion.

opOpAssign
BigInt opOpAssign(size_t shift)
putCoefficient
void putCoefficient(size_t value)
toString
immutable(C)[] toString()
toString
void toString(W w)
view
BigIntView!size_t view()
view
BigIntView!(const size_t) view()

Static functions

fromHexString
BigInt fromHexString(const(char)[] str)

Variables

data
size_t[ulong.sizeof / size_t.sizeof * maxSize64] data;
length
uint length;
sign
bool sign;

Parameters

maxSize64

count of 64bit words in coefficient

Examples

import mir.bignum.fixed;
import mir.bignum.low_level_view;

auto a = BigInt!4.fromHexString("4b313b23aa560e1b0985f89cbe6df5460860e39a64ba92b4abdd3ee77e4e05b8");
auto b = BigInt!4.fromHexString("c39b18a9f06fd8e962d99935cea0707f79a222050aaeaaaed17feb7aa76999d7");
auto c = BigInt!4.fromHexString("7869dd864619cace5953a09910327b3971413e6aa5f417fa25a2ac93291b941f");
c.sign = true;
assert(a != b);
assert(a < b);
a -= b;
assert(a.sign);
assert(a == c);
a -= a;
assert(!a.sign);
assert(!a.length);

auto d = BigInt!4.fromHexString("0de1a911c6dc8f90a7169a148e65d22cf34f6a8254ae26362b064f26ac44218a");
assert((b *= 0x7869dd86) == 0x5c019770);
assert(b == d);

d = BigInt!4.fromHexString("856eeb23e68cc73f2a517448862cdc97e83f9dfa23768296724bf00fda7df32a");
auto o = b *= UInt!128.fromHexString("f79a222050aaeaaa417fa25a2ac93291");
assert(o == UInt!128.fromHexString("d6d15b99499b73e68c3331eb0f7bf16"));
assert(b == d);

d = BigInt!4.fromHexString("d"); // initial value
d.mulPow5(60);
c = BigInt!4.fromHexString("81704fcef32d3bd8117effd5c4389285b05d");
assert(d == c);

d >>= 80;
c = BigInt!4.fromHexString("81704fcef32d3bd8");
assert(d == c);

c = BigInt!4.fromHexString("c39b18a9f06fd8e962d99935cea0707f79a222050aaeaaaed17feb7aa76999d7");
d = BigInt!4.fromHexString("9935cea0707f79a222050aaeaaaed17feb7aa76999d700000000000000000000");
c <<= 80;
assert(d == c);
c >>= 80;
c <<= 84;
d <<= 4;
assert(d == c);
assert(c != b);
b.sign = true;
assert(!c.copyFrom(b.view));
assert(c == b);
b >>= 18;
auto bView = cast(BigIntView!ushort)b.view;
assert(!c.copyFrom(bView.topLeastSignificantPart(bView.unsigned.coefficients.length - 1)));
assert(c == b);

Meta