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

Dale Buckley dalebuckley86 at gmail.com
Sat Feb 13 16:53:28 CST 2016


That’s a very interesting link and it’s nice to know that some kind of Decimal type already been considered, I had no idea. 

I can see why it’s been pushed back to a Swift 4 feature though, I would imagine the concentration is all about making the core of the language work as well as possible on Apple platforms first, and then thinking about the missing parts later. It’s just unfortunate that linux based systems have to rely on 3rd party solutions for now when it seems inevitable that the type will get added in at some point. But I guess Swift is still such a young language and it'll takes a while to catch up in some more "boring" areas.



> Cc:Dale Buckley<dalebuckley86 at gmail.com>
> Subject:[swift-evolution] Is there a need for a Decimal type?
> Date:13 February 2016 at 20:30:27 GMT
> 
> 
> 
> > 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