[swift-evolution] [swift-users] Replacement for NSNumber?

Jordan Rose jordan_rose at apple.com
Mon Apr 11 11:08:52 CDT 2016


This comes up often enough that we should probably write it somewhere, but we don't have this protocol for the simple reason that there are very few algorithms that are correct for both integers and floating-point numbers. Even something as simple as "average" needs to be handled differently.

Jordan


> On Apr 11, 2016, at 9:04 , Ross O'Brien via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Your pointing to two mutually exclusive protocols proves the point. If I want to write a generic function for a numerical type which can be added, I can't just require that the type conforms to IntegerArithmeticType because that excludes all the floating point types. Protocols for various numerical functions, e.g. NumericalArithmeticType, would be handy,
> 
> On Mon, Apr 11, 2016 at 4:55 PM, Joanna Carter via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> > It’s inconvenient that structs can’t inherit, and so things like Int and Double aren’t known as numbers. Should there be a Number protocol that encompasses all things number-like?
> 
> Taje a look at the IntegerType and FloatingPointType
> 
> --
> Joanna Carter
> Carter Consulting
> 
> (de mon iPhone)
> 
> _______________________________________________
> 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
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list