<div>On Sun, Jun 18, 2017 at 05:30 Ben Rimmington <<a href="mailto:me@benrimmington.com">me@benrimmington.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Re: <<a href="https://gist.github.com/xwu/d68baefaae9e9291d2e65bd12ad51be2#integers-from-a-floating-point-source" rel="noreferrer" target="_blank">https://gist.github.com/xwu/d68baefaae9e9291d2e65bd12ad51be2#integers-from-a-floating-point-source</a>><br>
<br>
There are also some commented-out requirements, which were accepted for SE-0067.<br>
<br>
(One requirement is obsoleted by the Numeric protocol).<br>
<br>
Can these be implemented yet, based on your experience?</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote><div><br></div><div>Based on a cursory thinking through only:</div><div><br></div><div>The first one, yes (if we observe that Integer is now BinaryInteger), but probably inefficiently as it would have to use `words`, I think. If the requirement were on BinaryFloatingPoint and T were constrained to BinaryInteger & FixedWidthInteger, I think it could be more efficient. Of course, both could be added. We could not remove the concrete initializer from a UInt source, though, as initializing from `words` would rely on that.</div><div><br></div><div>The second one, I think so, but I haven't tried to make sure.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
FloatingPoint<br>
-------------<br>
<br>
<<a href="https://github.com/apple/swift/blob/5ec0563c167a720e8c2c99390df6e032a24f2403/stdlib/public/core/FloatingPoint.swift.gyb#L256-L273" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/5ec0563c167a720e8c2c99390df6e032a24f2403/stdlib/public/core/FloatingPoint.swift.gyb#L256-L273</a>><br>
<br>
> /* TODO: Implement the following APIs once a revised integer protocol is<br>
> introduced that allows for them to be implemented. In particular, we<br>
> need to have an "index of most significant bit" operation and "get<br>
> absolute value as unsigned type" operation on the Integer protocol.<br>
><br>
> /// Creates the closest representable value to the given integer.<br>
> ///<br>
> /// - Parameter value: The integer to represent as a floating-point value.<br>
> init<Source: Integer>(_ value: Source)<br>
><br>
> /// Creates a value that exactly represents the given integer.<br>
> ///<br>
> /// If the given integer is outside the representable range of the type, the<br>
> /// result is `nil`.<br>
> ///<br>
> /// - Parameter value: The integer to represent as a floating-point value.<br>
> init?<Source: Integer>(exactly value: Source)<br>
> */<br>
<br>
BinaryFloatingPoint<br>
-------------------<br>
<br>
<<a href="https://github.com/apple/swift/blob/5ec0563c167a720e8c2c99390df6e032a24f2403/stdlib/public/core/FloatingPoint.swift.gyb#L1476-L1491" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/5ec0563c167a720e8c2c99390df6e032a24f2403/stdlib/public/core/FloatingPoint.swift.gyb#L1476-L1491</a>><br>
<br>
> /* TODO: Implement these once it becomes possible to do so (requires revised<br>
> Integer protocol).<br>
> /// Creates a new instance from the given value, rounded to the closest<br>
> /// possible representation.<br>
> ///<br>
> /// - Parameter value: A floating-point value.<br>
> init<Source: BinaryFloatingPoint>(_ value: Source)<br>
><br>
> /// Creates a new instance equivalent to the exact given value.<br>
> ///<br>
> /// If the value you pass as `value` can't be represented exactly, the result<br>
> /// of this initializer is `nil`.<br>
> ///<br>
> /// - Parameter value: A floating-point value to represent.<br>
> init?<Source: BinaryFloatingPoint>(exactly value: Source)<br>
> */<br>
<br>
</blockquote></div></div>