Decimal floating-point
stephentyrone opened this issue ยท 7 comments
Implement IEEE 754 Decimal128 (and possibly Decimal64 as well, though it's less important). This has a dependency on fixed-width integer types because we want to be able to leverage UInt128 arithmetic for the implementation.
We would like to second the request for this feature. For financial applications where values will not exceed the limits of UInt128 and where precision in values is key, having a Decimal128 implementation (or Decimal64) would be very helpful.
I agree with @paulrs that Decimal128 would be extremely valuable for financial applications.
Especially since Foundation's Decimal causes a fatal error in this simple case:
let d = Decimal(exactly: 0)
and Apple seems unwilling to fix it (I reported it January 17, 2021).
@jasonbobier The fatal error was simply that the API was unimplemented; it's been implemented in the open-source swift-corelibs-foundation for some years now and Apple's proprietary implementation will pick up the changes on some timeline of their choosing.
@xwu sigh "Some timeline of their choosing" is accurate. I have bugs from 2003 still open with them.
Is there any update on this?
I have an implementation of this including Decimal32, Decimal64, and Decimal128. Decimal32 is mostly tested but the other implementations require testing. This is a pure Swift implementation based on the Intel Corp Decimal Floating-Point Math Library v2.2. BTW, this is a IEEE 754 implementation.
It supports both BID (Binary Integer Decimal) and DPD (Densely Packed Decimal) encodings. IEEE 754 allows both encodings.
How would I upload this code so others can contribute? See https://github.com/mgriebling/MGDecimal for details.