<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Apr 2, 2017, at 11:19 PM, David Hart &lt;<a href="mailto:david@hartbit.com" class="">david@hartbit.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Any reason we need to burden ourselves with the two's complement representation?</div></div></blockquote><div><br class=""></div><div>The `words` collection and its two's-complement representation come straight out of the `BinaryInteger` protocol; all integer types already "speak" in variable-length two's-complement&nbsp;words. So having our literal protocol also speak the same language seems like a good way to leverage code that's already in the standard library. Besides, I can't think of a better universal format—the world has largely settled on two's complement for signed integers.</div><br class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><div class="">(There are a few similar approaches we could take, like exposing an `init(words:)` constructor in `BinaryInteger` and having the `IntegerLiteral` behave as a `Words` collection, but all of them basically involve bootstrapping into `BinaryInteger` through the `Words` type.)</div><div class=""><br class=""></div><div class="">I *think* that the not-yet-implemented `BinaryFloatingPoint.init&lt;Source:&nbsp;BinaryFloatingPoint&gt;(_&nbsp;value: Source)` initializers could be leveraged in a similar way—create a `BinaryFloatingPointSource` protocol and a `BinaryFloatLiteral` type that conforms to it—but I'm less certain of that because I don't really understand how this universal float conversion is supposed to work. Plus, the universal float conversion is still just a TODO comment right now.</div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">What do you mean by the universal float conversion?</div></div></blockquote></div><div class=""><br class=""></div><div class="">SE-0067 includes these `BinaryFloatingPoint` members which aren't in Swift yet:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp;&nbsp;//&nbsp; NOTE: --------------------------------------------------------------------<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&nbsp;//&nbsp; The next two APIs are not implementable without a revised integer<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&nbsp;//&nbsp; protocol. &nbsp;Nonetheless, I believe that it makes sense to consider them<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&nbsp;//&nbsp; with the rest of this proposal, with the understanding that they will<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&nbsp;//&nbsp; be implemented when it becomes possible to do so.<br class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; ///&nbsp;`value` rounded to the closest representable value.</div><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&nbsp;init&lt;Source:&nbsp;BinaryFloatingPoint&gt;(_&nbsp;value: Source)<div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; ///&nbsp;Fails if `value` cannot be represented exactly as `Self`.</div><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&nbsp;init?&lt;Source:&nbsp;BinaryFloatingPoint&gt;(exactly&nbsp;value: Source)<br class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; //&nbsp; --------------------------------------------------------------------------</div></div><div class=""><br class=""></div><div class="">These are what I refer to as "universal float conversion": they allow you to convert from any `BinaryFloatingPoint` type to any other `BinaryFloatingPoint` type, even if the two types aren't aware of each other's existence.</div><div class=""><br class=""></div><div class="">In principle, I believe we could do something similar to what I proposed for `BinaryInteger`: extract a `BinaryFloatingPointSource` super-protocol from `BinaryFloatingPoint` containing the members these initializers rely upon, modify these initializers to constrain their parameter to that new protocol, and use that to make a `BinaryFloatingPointLiteral` type. However, since these calls have not been implemented yet and I don't know which parts of `BinaryFloatingPoint` they're supposed to use, I can't really give a design for that.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">--&nbsp;</div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>

</div>
<br class=""></body></html>