fixedpoint 0.0.5

Decimal fixed point type


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

FixedPoint

FixedPoint provides a simple decimal fixed point type for the D language.

Usage

import std.conv : to;
import fixedpoint.fixed : Fixed;

alias MyFixed = Fixed!4;

void main()
{
    auto f1 = MyFixed("21.5");
    assert(f1.toString == "21.5000");
    assert(f1.to!int == 21);
    assert(f1.to!double == 21.5);
    assert(f1 + 1 == MyFixed("22.5"));
    assert(f1 + 1 == MyFixed("22.5"));
    auto f2 = MyFixed("20.5");
    assert(f1 > f2);
    assert(f1+f2 == MyFixed("42"));
}

Future Work

I plan to expand FixedPoint with an 'arithmetic' module, for easier handling of fixed-point arithmetic. Especially for arithmetic, where the scale of the fixed point might change, in order to keep the information.

There are similar packages which provide some kind of fixed-point types and arithmetic. However they don't seem to be maintained, or are too big for my purposes. There is fixed, which is very similar and inspired this project. stdxdecimal seems to have same goals as well. For arbitrary precision, you might want to try bigfixed. decimal is the IEEE-754-2008 compliant decimal data type.

Licence

FixedPoint is released with the Boost license (like most D projects). See here for more details.

Authors:
  • Jan Hönig
Dependencies:
none
Versions:
0.0.5 2020-Jan-29
0.0.4 2020-Jan-21
0.0.3 2020-Jan-17
0.0.2 2019-Dec-29
0.0.1 2019-Dec-29
Show all 6 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 6 downloads this month

  • 21 downloads total

Score:
0.6
Short URL:
fixedpoint.dub.pm