stdxdecimal 0.3.0

Proposal for a General Decimal Arithmetic type to Phobos


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Decimal Type for Phobos

This code is a work in progress for a new type Decimal that follows the "General Decimal Arithmetic Specification" http://speleotrove.com/decimal/decarith.html

Current Features

FeatureImplemented
Construction from strings/string-like ranges
Construction from number types
To decimal string
To scientific string
To engineering string
All rounding types
Overflow/Underflow Behavior
Subnormal Behavior
Equals
Compare
Addition/Subtraction
Multiply
Divide
Unary Plus/Minus/Increment/Decrement
Cast Int/Float/Bool
abs
ln
log10
exp
sqrt
power
reduce

Example

import stdxdecimal;

void main()
{
    auto d1 = decimal("1.23");
    auto d2 = decimal("1.23E-4");
    auto d3 = decimal("1.23E4");

    assert(d1.toString() == "1.23");
    assert(d2.toString() == "0.000123");
    assert(d3.toString() == "12300");

    auto d4 = d1 + d2;
    assert(d4.toString() == "1.230123");

    auto d5 = d3 - d1;
    assert(d5.toString() == "12298.87");

    auto d6 = decimal!(HighPrecision)("1.000000000000000000000000000000000000000000000000001");
}
Authors:
  • Jack Stouffer
Dependencies:
none
Versions:
0.5.0 2018-Jan-05
0.4.0 2017-Dec-21
0.3.0 2017-Dec-08
0.2.0 2017-Dec-06
0.1.0 2017-Dec-02
Show all 6 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 26 downloads this month

  • 472 downloads total

Score:
1.2
Short URL:
stdxdecimal.dub.pm