<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 29, 2017, at 4:41 AM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 14px; 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-stroke-width: 0px;" class="">&nbsp;</div><blockquote class="gmail_quote" style="font-family: Helvetica; font-size: 14px; 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-stroke-width: 0px; margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">&gt;&nbsp; &nbsp;static func doubleWidthMultiply(_ lhs: Self, _ rhs: Self) -&gt; (high: Self, low: Magnitude)<br class="">&gt;&nbsp; &nbsp;static func doubleWidthDivide(_ lhs: (high: Self, low: Magnitude), _ rhs: Self) -&gt; (quotient: Self, remainder: Self)<br class=""><br class="">Could these take/return a single `DoubleWidth&lt;Self&gt;` value instead of two separate `Self` and `Magnitude` values? Or would that present circularity problems?</blockquote><div style="font-family: Helvetica; font-size: 14px; 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-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px; 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-stroke-width: 0px;" class="">Having mulled the idea of implementing an IEEE Decimal type, I'd be sad to see these return DoubleWidth&lt;Self&gt;. Double-width multiply as it is here is useful when you want to get the result and immediately discard either the high or the low bits, for instance.&nbsp;If you'd want a result of type `DoubleWidth&lt;Foo&gt;` instead, you could always just write `DoubleWidth&lt;Foo&gt;(a) * DoubleWidth&lt;Foo&gt;(b)`.</div></div></blockquote></div><br class=""><div class="">doubleWidthDivide should not return a DoubleWidth&lt;T&gt; for two reasons:</div><div class="">1. The components of it’s return type are not high and low, but are quotient and remainder instead.</div><div class="">2. In DoubleWidth&lt;T&gt; high is T and low is T.Magnitude, which is not the case for quotient and remainder.</div><div class=""><br class=""></div><div class="">Having said that, there is a solution for doubleWidthMultiply, that I think is worth trying:</div><div class=""><br class=""></div><div class="">enum DoubleWidth&lt;T&gt; {</div><div class="">&nbsp; case .parts(high: T, low: T.Magnitude)</div><div class=""><br class=""></div><div class="">&nbsp; var high: T { switch self { case .parts(let high, _): return high } }</div><div class="">&nbsp; var low: T.Magnitude { switch self { case .parts(_, let low): return low } }</div><div class="">}</div><div class=""><br class=""></div><div class="">This way it will be possible to both do pattern-matching on the result of doubleWidthMultiply, and use it as a whole, accessing r.high and r.low when needed.</div><div class=""><br class=""></div><div class="">Max</div></body></html>