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 > <[email protected]> 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 > <[email protected] <mailto:[email protected]>> 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 > [email protected] <mailto:[email protected]> > https://lists.swift.org/mailman/listinfo/swift-evolution > <https://lists.swift.org/mailman/listinfo/swift-evolution> > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
