stdxdecimal 0.3.0

Proposal for a General Decimal Arithmetic type to Phobos


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

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

Feature | Implemented ------------ | ------------- 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.3.0 2017-Dec-08
0.2.0 2017-Dec-06
0.1.0 2017-Dec-02
~master 2017-Dec-15
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 2 downloads this week

  • 2 downloads this month

  • 2 downloads total