Number

Class to represent Numbers in dutils.

Constructors

this
this(NumberContainer num)

Constructs a Number.

this
this(ulong precision)

Constructs a Number using precision only.

Members

Functions

applyOp
bool applyOp(dstring op, Mtype!W rhs)

Applies an operator to a Number given the rhs.

applyOpResult
Number applyOpResult(dstring op, Mtype!W rhs)

The result of applying an operator to a Number.

fromDstring
void fromDstring(dstring from)

Serializes a dstring to a Number.

opEquals
bool opEquals(Number rhs)

Detrmine if two Numbers are equal.

toDstring
dstring toDstring()

Represents a Number as a dstring.

Examples

BigInt a = 1;
immutable BigInt b = -1;
immutable long c = 0;
Number e = new Number(NumberContainer(a,b,c));
a = 2;
Number f = new Number(NumberContainer(a,b,c));
e.applyOp("/", f);
assert(e.val == NumberContainer(BigInt(6), BigInt(-2), -1L));
assert(e.toDstring == ".6-.2i"d);
f = new Number(NumberContainer(BigInt(6), BigInt(0), 1L));
assert(f.toDstring == "60+00i"d);
auto g = f.toDstring;
f.fromDstring(g);
assert(f.toDstring == g, cast(char[])f.toDstring.dup);
f = new Number(NumberContainer(BigInt(6), BigInt(0), -2L));
assert(f.toDstring == ".06+.00i"d, cast(char[])f.toDstring.dup);
g = f.toDstring;
f.fromDstring(g);
assert(g == f.toDstring);
f = new Number(NumberContainer(BigInt(3), BigInt(6), -23L));
g = f.toDstring;
f.fromDstring(g);
assert(g == f.toDstring);
f = new Number(NumberContainer(BigInt(6), BigInt(0), 0L));
assert(f.toDstring == "6+0i"d);
f = new Number(NumberContainer(BigInt(60), BigInt(0), -1L));
assert(f.toDstring == "6.0+.0i"d, cast(char[])f.toDstring.dup);

Meta