Decimal

Stack-allocated decimal type.

Constructors

this
this(const(C)[] str, int exponentShift)
this
this(T x)

Constructs Decimal from the floating point number using the Ryu algorithm.

Members

Functions

fromStringImpl
bool fromStringImpl(const(C)[] str, DecimalExponentKey key, int exponentShift)
fromStringWithThousandsSeparatorImpl
bool fromStringWithThousandsSeparatorImpl(const(C)[] str, C thousandsSeparator, C fractionSeparator, DecimalExponentKey key, int exponentShift)

Handle thousand separators for non exponential numbers.

isInfinity
bool isInfinity()
isNaN
bool isNaN()
opAssign
ref opAssign(Decimal!rhsMaxSize64 rhs)
opCast
T opCast()

Mir parsing supports up-to quadruple precision. The conversion error is 0 ULP for normal numbers. Subnormal numbers with an exponent greater than or equal to -512 have upper error bound equal to 1 ULP.

opOpAssign
ref opOpAssign(Decimal!rhsMaxSize64 rhs)
toString
immutable(C)[] toString(NumericSpec spec)
toString
void toString(W w, NumericSpec spec)
view
DecimalView!size_t view()
DecimalView!(const size_t) view()

Variables

coefficient
BigInt!maxSize64 coefficient;
exponent
sizediff_t exponent;

Parameters

maxSize64

count of 64bit words in coefficient

Examples

import mir.conv: to;
Decimal!3 decimal;
DecimalExponentKey key;

import mir.math.constant: PI;
assert(decimal.fromStringImpl("3.141592653589793378e-10", key));
assert(cast(double) decimal == double(PI) / 1e10);
assert(key == DecimalExponentKey.e);
import mir.conv: to;
Decimal!3 decimal;
DecimalExponentKey key;

assert(decimal.fromStringImpl("0", key));
assert(key == DecimalExponentKey.none);
assert(decimal.exponent == 0);
assert(decimal.coefficient.length == 0);
assert(!decimal.coefficient.sign);
assert(cast(double) decimal.coefficient == 0);

assert(decimal.fromStringImpl("-0.0", key));
assert(key == DecimalExponentKey.dot);
assert(decimal.exponent == -1);
assert(decimal.coefficient.length == 0);
assert(decimal.coefficient.sign);
assert(cast(double) decimal.coefficient == 0);

assert(decimal.fromStringImpl("0e0", key));
assert(key == DecimalExponentKey.e);
assert(decimal.exponent == 0);
assert(decimal.coefficient.length == 0);
assert(!decimal.coefficient.sign);
assert(cast(double) decimal.coefficient == 0);

Meta