swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

Consider fate of `Decimal`

Open parkera opened this issue 2 years ago • 4 comments
trafficstars

Decimal is used by a few core types in Essentials, but it probably also needs some updates to be a better citizen in Swift. In ObjC it is a C struct, so it would be difficult to share the sources exactly.

parkera avatar Apr 18 '23 20:04 parkera

It also crashes because of missing functionality.

Decimal(exactly: 0)

jasonbobier avatar Apr 27 '23 08:04 jasonbobier

Most of the missing functionality was implemented in the open-source version; it was to be synchronized with the Apple version but...well, that hasn't happened. If made part of a new open-source project across all platforms, one can be confident that the missing functionality will not be an issue.

More saliently, though, the Decimal type pre-dates modern IEEE decimal types, and it is likely that we will want those, so it is wise to consider carefully where the legacy type best fits into the picture.

xwu avatar Apr 28 '23 17:04 xwu

I remember you mentioning that when I wrote the initial bug. imo, it definitely makes sense to phase out the old legacy Decimal as I don't see any advantages over the IEEE format. One issue that we all encounter with floating points is that at times it is important to know if a number could accurately be represented when doing arithmetic in order to avoid propagating rounding errors.

jasonbobier avatar Apr 28 '23 17:04 jasonbobier

Added a discussion in the swift forums here: https://forums.swift.org/t/consider-fate-of-decimal/64708

jasonbobier avatar Apr 30 '23 10:04 jasonbobier