[swift-evolution] Is there a need for a Decimal type?

Mark Glossop lists at cueballcentral.com
Sat Feb 13 14:30:27 CST 2016


> On 13 Feb 2016, at 19:51, Dale Buckley via swift-evolution <swift-evolution at swift.org> wrote:
> 
> We all know the problems with floating point types, they are well documented and well understood by developers everywhere. We know when to use them and (hopefully) when not to use them and if you are working with financial values on a Foundation based platform you know to not use a floating point type and to use NSDecimalNumber instead.
> 
> My question is this; should there be an equivalent NSDecimalNumber type built into Swift that can be used for precision sensitive decimal values where floating point types can’t be used?
> 
> Maybe the answer isn’t an ‘equivalent’ as such, it would probably have a modern twist so I can see it looking like something else entirely, but the point still stands.
> 
> I feel like there is a need for this, it’s not a new problem and has been solved many times over in other languages such as Objective-C (NSDecimalNumber) and Java (BigDecimal) etc. Yet as it stands we seem to be lacking an equivalent solution in Swift. It shouldn’t be left for an external library to solve, it’s one of those things that need to be built into the language.
> 
> What are peoples thoughts on this?

Relevant (and because I remember it since Steve was replying to my message at the time):

	https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/005782.html

>> On Jan 7, 2016, at 12:40 PM, Mark Glossop via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Sidebar on decimal numerics since they're relevant to support for currency units - would be nice to know if the "new" IEEE 754 (2008) Decimal floating-point types are in the Swift roadmap?
>> My suspicion is that any support for them will only come from upstream in LLVM as a first-class type [quad precision/binary128 is supported as the fp128 type; but no decimal floating-point types at present] - so looks like any fixed-point decimal support in the interim would need to be provided by hacking int types, but if anyone wants to chime in... :-)
> 
> Decimal FP is somewhere in the hazy far-future hypothetical roadmap.  It’s actually far more useful than (software) Binary128; implemented in software the performance delta between the two is fairly narrow on modern CPU architectures (except possibly for division), and having a decimal FP type available would be quite nice.
> 
> There’s a lot of lower-hanging fruit to chip away on first, however.
> – Steve

So - it's in the "far-future hypothetical roadmap". I've taken that to mean somewhere past Swift 4, whenever that drops.

In the meantime you might check out PONS which was mentioned a few days ago: https://github.com/dankogai/swift-pons - haven't tried it myself yet, but it appears to be an option for BigNums and Rational types ("decimal" types being a subset of Rational functionality.)

FWIW a number of other prior posts that mention dedicated decimal types:

	https://www.google.com.au/search?q=decimal+AND+type+site:https://lists.swift.org/pipermail/swift-evolution/

HTH,
M.
-- 
Mark Glossop
E: lists at cueballcentral.com
TW: http://twitter.com/Cueball_AU


More information about the swift-evolution mailing list