BigFloat or BigDecimal?

Paul D. Anderson paul.d.removethis.anderson at comcast.andthis.net
Tue Jun 14 11:36:33 PDT 2011


I've been working feverishly to generate an implementation of the General Decimal Arithmetic specification (http://www.speleotrope.com/decimal). This will provide arbitrary precision (AP) floating point arithmetic, as well as fixed length (32, 64, and 128 bits) decimal floating point numbers.

My intention a couple of weeks ago was to tidy it up slightly and publish a level 0.1 release, but I keep postponing it for another round of fixes. Apparently this is a never-ending process, so I will make it available, warts and all.

The git address is: https://github.com/andersonpd/decimal.git

At this point it is just a snapshot of a work in progress, but it's not far from being usable. My intention is to have a working implementation of the AP numbers and the 32- and 64-bit fixed numbers by the 4th of July.

There is already a more or less complete implementation of the AP floats (exclusive of logical ops and exp, log, and power) and some scraps of implementation of fixed-length numbers.

I have some bikeshed sort of questions regarding both naming and implementation and I'd like some feedback from the community:

1) I've named the AP numbers "Decimal", but a better name is either "BigDecimal" or "BigFloat". I'm leaning toward BigDecimal. The fixed size numbers are "Dec32", "Dec64" and "Dec128". Are these names satisfactory?

2) There are two available representations for the fixed size numbers: densely packed decimals and binary integer decimals. If anyone knows or cares about the difference do you have a preference? The binary integer decimals are much simpler to convert to other types, so I'm implementing those, but it's not much work to implement the others. If you want more info I can point you to references.

3) The current design is to back all the fixed size numbers with the AP numbers. That is, the fixed sized are converted to arbitrary precision, operated on, and coverted back. The AP numbers are based on std.bigint.BigInt, so all internal math is performed using BigInts. It is possible, however, to use uints and ulong arithmetic for Dec32 and Dec64, respectively. But the ints and longs would have to indicate overflow, etc., so it's not trivial. (I wish there were CheckedInt struct!) The first releases will use BigInts, but is it worthwhile to pursue the other?

Any questions or ideas please e-mail me at the address above. (I won't be able to check my e-mail until this evening (PDT), so if you want a quicker response use this forum.)

Paul



More information about the Digitalmars-d mailing list