<p dir="ltr">On 3 Jul 2014 23:00, "Paul D Anderson via Digitalmars-d-announce" <<a href="mailto:digitalmars-d-announce@puremagic.com">digitalmars-d-announce@puremagic.com</a>> wrote:<br>
><br>
> A candidate implementation of decimal numbers (arbitrary-precision<br>
> floating-point numbers) is available for review at<br>
> <a href="https://github.com/andersonpd/eris/tree/master/eris/decimal">https://github.com/andersonpd/eris/tree/master/eris/decimal</a>. This is a<br>
> substantial rework of an earlier implementation which was located at<br>
> <a href="https://github.com/andersonpd/decimal">https://github.com/andersonpd/decimal</a>.<br>
><br>
> This is a D language implementation of the General Decimal Arithmetic<br>
> Specification (<a href="http://www.speleotrove.com/decimal/decarith.pdf">http://www.speleotrove.com/decimal/decarith.pdf</a>), which is<br>
> compliant with IEEE-754 and other standards as noted in the specification.<br>
><br>
> The current implementation is not complete; there are a lot of TODOs and NOTEs<br>
> scattered throughout the code, but all the arithmetic and miscellaneous<br>
> operations listed in the spec are working, along with decimal versions of most<br>
> of the functions and constants in std.math. I think it is far enough along for<br>
> effective review.<br>
><br>
> Briefly, this software adds the capability of properly rounded<br>
> arbitrary-precision floating-point arithmetic to the D language. All arithmetic<br>
> operations are governed by a "context", which specifies the precision (number of<br>
> decimal digits) and rounding mode for the operations. This same functionality<br>
> exists in most modern computer languages (for example, java.math.BigDecimal).<br>
> Unlike Java, however, which uses function syntax for arithmetic ops<br>
> (add(BigDecimal, BigDecimal), etc.), in D the same arithmetic operators that<br>
> work for floats or doubles work for decimal numbers. (Of course!)<br>
><br>
> In this implementation decimal numbers having different contexts are different<br>
> types. The types are specified using template parameters for the precision,<br>
> maximum exponent value and rounding mode. This means that<br>
> Decimal!(9,99,Rounding.HALF_EVEN) is a different type than<br>
> Decimal!(19,199,Rounding.HALF_DOWN). They are largely interoperable, however.<br>
> Different decimal types can be cast to and from each<br>
> other.<br>
><br>
> There are three standard decimal structs which fit into 32-, 64- and 128-bits of<br>
> memory, with 7, 16 and 34 digit precision, respectively. These are used for<br>
> compact storage; they are converted to their corresponding decimal numbers for<br>
> calculation. They bear the same relation to decimal numbers as Walter's<br>
> half-float type does to floats.<br>
> (<a href="http://www.drdobbs.com/cpp/implementing-half-floats-in-d/240146674">http://www.drdobbs.com/cpp/implementing-half-floats-in-d/240146674</a>).<br>
> Implementation of these still needs a little work, and will be added to github<br>
> very shortly.<br>
><br>
> Major TODO items:<br>
><br>
> 1) The current underlying integer type uses my own big integer struct<br>
> (eris.integer.extended) rather than std.bigint. This was mainly due to problems<br>
> with constness and CTFE of BigInts. These problems have since been resolved, but<br>
> I didn't want to switch over to BigInts until everything was working for fear of<br>
> introducing new bugs.<br>
><br>
> 2) Integration of Decimal32, Decimal64 and Decimal128 structs are not complete.<br>
> (See above.)<br>
><br>
> 3) Conversion to and from floats, doubles and reals is currently working but it<br>
> is slow. (Conversion is through strings: double to string to decimal and vice<br>
> versa.)<br>
><br>
> 4) Still incomplete implementations of some functions in decimal.math: expm1,<br>
> acosh, atanh, possibly others.<br>
><br>
> 5) More unit tests (always!).</p>
<p dir="ltr">Nice job. </p>
<p dir="ltr">I would also add:</p>
<p dir="ltr">6) Rename the file decimal.d to package.d, and module eris.decimal.decimal to eris.decimal<br>
</p>