[swift-evolution] [Proposal draft] Enhanced floating-point protocols

plx plxswift at icloud.com
Fri Apr 15 09:23:48 CDT 2016


+1; this is great!

I have nothing but good things to say about the proposal itself.

I have two smaller questions, however; I apologize if they are off-topic.

One is if there’s any ETA or similar for a glimpse at the “complete picture” of Swift’s revised numeric protocols; these floating-point protocols look really, really good, but this is also (I think) the first glimpse at the new `Arithmetic` protocol, and there’s also a new “Integer” protocol coming…and it’d be nice to get a sense of the complete vision here.

My other question is potentially subsumed by the above, but I want to raise it now: it’d be great if there was some standardized protocol/vocabulary to use when converting between various numeric representations that was:

- easy for custom numeric types to *adopt* correctly (e.g. if one were to write a fixed-point type, or a rational type, etc.)
- easy for non-experts to *use* correctly for non-expert purposes

…since such conversions from one representation to another are at least IMHO a dangerous area; if you know what you’re doing it’s not dangerous, but e.g. even if someone is only trying to go from Double -> Int:

- they probably aren’t an expert, doing expert numerical things
- they may not have a solid understanding of floating point (NaN, infinities, etc.)
- they thus may not know they may *need* to be careful here
- they may not know *how* to be careful, even if they know they *should* be
- they may not be able to be careful *correctly*, even if they attempt it

…and so it’d again be great if the revised numeric protocols allow as broad a range of such conversions as possible to be handled by generic code in the standard library. 

It certainly looks like `FloatingPoint` protocol itself provides enough information to allow an expert to write generic version of most floating point -> integer conversion variants I can think of, but I’m not an expert…but it’d be great if e.g. there was some simpler protocol other custom numeric types could adopt to take advantage of expert-written generic conversions to other numeric types. 

I can provide examples if this is unclear, and if it’s off-topic it can wait for another time. 

This `FloatingPoint` revision itself looks really really good! 

> On Apr 14, 2016, at 6:55 PM, Stephen Canon via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Enhanced floating-point protocols
> 


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


More information about the swift-evolution mailing list