[swift-evolution] [swift-evolution-announce] [Review] SE-0080: Failable Numeric Conversion Initializers

Stephen Canon scanon at apple.com
Wed May 4 10:45:16 CDT 2016


First, a general +1 to these, thanks for proposing them.

In SE-0067 we spelled these “exactly” rather than “exact”.
init?<Source: Integer>(exactly value: Source)

As for –0, Int(exactly: -0.0) should *not* fail.  My rationale for this is as follows:

- While information (the signbit) is lost, the essential property is that `Double(Int(exactly: -0.0)) == -0.0`.
- If we instead adopted “no information loss” as a criteria, we would back ourselves into a corner w.r.t decimal floating-point types, which have multiple representations of most values (1.0 can be encoded as 1e0 or 10e-1 or 100e-2 …).  The result would be that these initializers would always fail for decimal fp inputs.

– Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160504/c796c485/attachment.html>


More information about the swift-evolution mailing list