<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 <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> 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=""> </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;">> static func doubleWidthMultiply(_ lhs: Self, _ rhs: Self) -> (high: Self, low: Magnitude)<br class="">> static func doubleWidthDivide(_ lhs: (high: Self, low: Magnitude), _ rhs: Self) -> (quotient: Self, remainder: Self)<br class=""><br class="">Could these take/return a single `DoubleWidth<Self>` 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<Self>. 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. If you'd want a result of type `DoubleWidth<Foo>` instead, you could always just write `DoubleWidth<Foo>(a) * DoubleWidth<Foo>(b)`.</div></div></blockquote></div><br class=""><div class="">doubleWidthDivide should not return a DoubleWidth<T> 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<T> 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<T> {</div><div class=""> case .parts(high: T, low: T.Magnitude)</div><div class=""><br class=""></div><div class=""> var high: T { switch self { case .parts(let high, _): return high } }</div><div class=""> 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>