swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.37k stars 152 forks source link

Consider fate of `Decimal` #43

Open parkera opened 1 year ago

parkera commented 1 year ago

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.

jasonbobier commented 1 year ago

It also crashes because of missing functionality.

Decimal(exactly: 0)

xwu commented 1 year ago

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.

jasonbobier commented 1 year ago

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 commented 1 year ago

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