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

Craig Cruden ccruden at novafore.com
Sat Feb 13 15:14:48 CST 2016


ok, found it….  woooooo….. 

ugly.  Sure this is not just suppose to be internal to NSDecimalNumber

Have not tried using it…. just let it fill in the defaults to see what it is.  Does not look like it is actually meant to be used outside of something that makes it friendly.

NSDecimal(_exponent: <#T##Int32#>, _length: <#T##UInt32#>, _isNegative: <#T##UInt32#>, _isCompact: <#T##UInt32#>, _reserved: <#T##UInt32#>, _mantissa: <#T##(UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16)#>)



> On 2016-02-14, at 4:08:51, Charles Kissinger <crk at akkyra.com> wrote:
> 
> 
>> On Feb 13, 2016, at 12:57 PM, Craig Cruden <ccruden at novafore.com <mailto:ccruden at novafore.com>> wrote:
>> 
>> You mean this (I cannot find NSDecimal)
> 
> 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.
> 
> I can understand why you would not want to use NSDecimalNumber.
> 
> —CK
> 
>> let y = NSDecimalNumber(string: "5")
>> 
>> y.decimalNumberByAdding(NSDecimalNumber(string: "10”))
>> 
>> Base values like this should not be mutable…..
>> 
>> And I could not find an NSDecimal implementation accessible from Swift (is there one)? (as such I cannot check that api). 
>> 
>> 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.
>> 
>> So you should have all the infix operations available, and the values themselves should not be mutable.
>> 
>> 
>> 
>> 
>> 
>>> On 2016-02-14, at 3:45:46, Charles Kissinger via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> 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?
>>> 
>>> —CK
>>> 
>>>> On Feb 13, 2016, at 3:51 AM, Dale Buckley via swift-evolution <swift-evolution at swift.org <mailto: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?
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160214/6a610901/attachment.html>


More information about the swift-evolution mailing list