<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Assuming RawSignificand really is the type you want, I think this does what you’re looking for?<br class=""><br class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures" class=""> BinaryFloatingPointWithBitPattern: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">BinaryFloatingPoint</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(bitPattern: RawSignificand)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bitPattern: RawSignificand { </span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">get</span><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(195, 89, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(54, 86, 138);" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">BinaryFloatingPointWithBitPattern</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;{ }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(195, 89, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(54, 86, 138);" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">BinaryFloatingPointWithBitPattern</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;{ }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(195, 89, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(195, 89, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">BinaryFloatingPointWithBitPattern</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(unitRangeFromRawSignificand s: RawSignificand) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">(bitPattern: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">).</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">bitPattern</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">|</span><span style="font-variant-ligatures: no-common-ligatures" class=""> s) </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">-</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #36568a" class="">1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><br class=""><blockquote type="cite" class="">On Aug 26, 2016, at 7:38 PM, Stephen Canon via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><br class="">Where does your RawSignificand input come from? &nbsp;Is that really the type that you want?<br class=""><br class="">I don’t think you really need very much boilerplate at all here.<br class=""><br class=""><blockquote type="cite" class="">On Aug 26, 2016, at 7:30 PM, Jens Persson &lt;<a href="mailto:jens@bitcycle.com" class="">jens@bitcycle.com</a>&gt; wrote:<br class=""><br class="">I understand.<br class="">It's just very tempting to try and use the new static computed properties for eg 23 and 52 etc.<br class="">I guess I'll just have to write a lot of boilerplate, or perhaps a protocol that is just implemented by Double and Float&nbsp;(that will be very similar to BinaryFloatingPoint in a lot of ways).<br class="">/Jens<br class=""><br class="">On Sat, Aug 27, 2016 at 1:25 AM, Stephen Canon&nbsp;&lt;scanon@apple.com&gt;&nbsp;wrote:<br class="">This doesn’t really scale up very well, though. &nbsp;BinaryFloatingPoint needs to also be able to model e.g. Float2048 or&nbsp;similar; we generally don't want to require that RawExponent to be the same type as RawSignificand (which I think is&nbsp;what you’re really suggesting), because in typical bignum usage significands are much larger than exponents.<br class=""><br class="">It sounds like maybe you actually want to be operating directly on bitPatterns, rather than the abstract fields of the&nbsp;types.<br class=""><br class="">– Steve<br class=""><br class=""><blockquote type="cite" class="">On Aug 26, 2016, at 7:21 PM, Jens Persson &lt;jens@bitcycle.com&gt; wrote:<br class=""><br class="">Oh, to more directly answer your question: I don't like having to create a UInt (UInt64) value when all my bit&nbsp;manipulaton code happens in UInt32 (for Float) for example.<br class=""><br class="">The most probable context for using these computed properties and types of BinaryFloatingPoint is one in which&nbsp;specific fixed width types really matters a lot (look at the name of the protocol and the properties and assocated&nbsp;types we are talking about).<br class=""><br class="">/Jens<br class=""><br class=""><br class="">On Sat, Aug 27, 2016 at 1:15 AM, Jens Persson&nbsp;&lt;jens@bitcycle.com&gt;&nbsp;wrote:<br class="">Reason for asking is that I have this:<br class=""><br class="">extension Double {<br class="">&nbsp; &nbsp; init(unitRangeFromRawSignificand s: RawSignificand) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; let bitPattern = s | (1023 &lt;&lt; 52)<br class="">&nbsp; &nbsp; &nbsp; &nbsp; self = unsafeBitCast(bitPattern, to: Double.self) - 1.0<br class="">&nbsp; &nbsp; }<br class="">}<br class="">extension Float {<br class="">&nbsp; &nbsp; init(unitRangeFromRawSignificand s: RawSignificand) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; let bitPattern = s | (127 &lt;&lt; 23)<br class="">&nbsp; &nbsp; &nbsp; &nbsp; self = unsafeBitCast(bitPattern, to: Float.self) - 1.0<br class="">&nbsp; &nbsp; }<br class="">}<br class=""><br class="">But they would be better as:<br class="">extension BinaryFloatingPoint {<br class="">&nbsp; &nbsp; init(unitRangeFromRawSignificand s: RawSignificand) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; ... problems here, have to try casting things into RawSignificand's type ...<br class="">&nbsp; &nbsp; }<br class="">}<br class=""><br class="">Please have a go at that and perhaps you see what I mean or you will come up with a nice solution that I have&nbsp;missed. (Speed is very important btw.)<br class=""><br class="">/Jens<br class=""><br class=""><br class="">On Sat, Aug 27, 2016 at 1:02 AM, Stephen Canon&nbsp;&lt;scanon@apple.com&gt;&nbsp;wrote:<br class="">&gt; On Aug 26, 2016, at 6:06 PM, Jens Persson via swift-dev &lt;swift-dev@swift.org&gt; wrote:<br class="">&gt;<br class="">&gt; I can understand why<br class="">&gt; Double.RawSignificand is UInt64<br class="">&gt; and<br class="">&gt; Float.RawSignificand is UInt32<br class="">&gt;<br class="">&gt; But I can't understand why both<br class="">&gt; Double.RawExponent<br class="">&gt; and<br class="">&gt; Float.RawExponent<br class="">&gt; should be UInt.<br class="">&gt;<br class="">&gt; Why aren't they also just UInt64 and UInt32, resp.?<br class=""><br class="">Let me flip the question: why would they be UInt64 and UInt32? &nbsp;Absent a reason to prefer a specific fixed-with type, Swift integers should generally default to being [U]Int (and ideally Int, but RawExponent is&nbsp;Unsigned).<br class=""><br class="">– Steve<br class=""><br class=""><br class=""></blockquote><br class=""><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></blockquote><br class=""></body></html>