Another take on decimal data types

rumbu rumbu at rumbu.ro
Mon Jan 8 22:16:25 UTC 2018


This is my first D finalized project (+16k loc).

I know that there are other two projects intended to provide a 
decimal data type for D, but I consider mine the most complete 
and most compliant to the standards (at least until now).

There are two years of since I'm working on it (and learning D in 
the same time), but I concentrated most of the efforts in the 
last two months.

It was a nice exercise because I was happy to remember the math I 
learn through my college years (trigonometry, logarithms, Taylor 
series, derivatives, etc). Unfortunately I'm not using the same 
math during my day-to day job.

Maybe in another post I will share my struggles I encountered 
during the development (plenty of). But a big thank you goes to 
Rainer Schuetze: without Visual Studio and without the integrated 
debugger this project was impossible to maintain.

Now on topic:

- fully IEEE-754-2008 compliant;
- one flat file;
- using Intel's binary decimal enconding;
- three decimal data types: decimal32, decimal64 and decimal128
- all D operators supported for all numeric types (left and right 
side integrals, floats, chars);
- conversion supported from/to integrals, floats, bools, chars
- conversion to/from other decimal formats (Microsoft Currency, 
Microsoft Decimal, IBM Densely Packed Decimal)
- all std.math functions implemented (even logarithms and 
trigonometry);
- all format specifiers implemented (%f, %e, %g, %a);
- integrated with phobos format and conversion functions (to, 
format, writef);
- thread local precision (from 1 to 34 decimal digits);
- new rounding mode - Europe's most used - tiesToAway;
- alternate exception handling (through flags);
- minimal dependencies (some traits and some floating point 
functions);
- comprehensive documentation;

Source code: 
https://github.com/rumbu13/decimal/blob/master/src/decimal.d

Documentation: http://rumbu13.github.io/decimal/doc/decimal.html

The project is more than in an alpha state, all operations were 
tested but not exhaustively.

What's next:
- more tests;
- benchmarks;




More information about the Digitalmars-d-announce mailing list