<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 13, 2016, at 12:57 PM, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" class="">ccruden@novafore.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You mean this (I cannot find NSDecimal)</div></div></blockquote><div><br class=""></div><div>Hmmm. NSDecimal is accessible to me in Xcode after importing Foundation. It’s included in the open source Foundation library as well. I’m not sure what is going on there.</div><div><br class=""></div><div>I can understand why you would not want to use NSDecimalNumber.</div><div><br class=""></div><div>—CK</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> y = <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSDecimalNumber</span>(string: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"5"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">y</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">.</span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(61, 29, 129);" class="">decimalNumberByAdding</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">(</span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(112, 61, 170);" class="">NSDecimalNumber</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">(string: </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(209, 47, 27);" class="">"10</span><font color="#d12f1b" face="Menlo" class=""><span style="font-size: 11px;" class="">”</span></font><font face="Menlo" class=""><span style="font-size: 11px;" class="">))</span></font></div><div class=""><br class=""></div><div class="">Base values like this should not be mutable…..</div><div class=""><br class=""></div><div class="">And I could not find an NSDecimal implementation accessible from Swift (is there one)? (as such I cannot check that api).&nbsp;</div><div class=""><br class=""></div><div class="">The only real difference between a Decimal and an Int is that Int / Float instructions exist in hardware, whereas Decimal has to be simulated - but is just a real type when programming in high level language.</div><div class=""><br class=""></div><div class="">So you should have all the infix operations available, and the values themselves should not be mutable.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 2016-02-14, at 3:45:46, Charles Kissinger via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Both the NSDecimalNumber class and the NSDecimal struct are already available in Swift. If there were a set of operators and initializers for NSDecimal, would that provide most of what you need? The operators would be simple to implement over the existing functions, I think. Maybe the corelibs people would take those as a patch?<br class=""><br class="">—CK<br class=""><br class=""><blockquote type="cite" class="">On Feb 13, 2016, at 3:51 AM, Dale Buckley via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">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.<br class=""><br class="">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?<br class=""><br class="">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.<br class=""><br class="">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.<br class=""><br class="">What are peoples thoughts on this?<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>