<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="font-size:13px">- I remain unconvinced that defining an Arithmetic that includes both exact and floating-point numbers is a good idea. All of the arguments from Swift 1 and 2 about why we didn't include this still seem relevant. To phrase it in generic programming terms, what algorithm would be generic over Arithmetic?</div></blockquote><div><br></div><div>E.g. generic point/size/rect types.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="im" style="font-size:13px">> For Integer, does the presence of signBit indicate an expectation that signed Integers will have a two's complement representation?<br></span><span style="font-size:13px">Yes. That is correct.</span></blockquote><div><br></div><div>So would this require a BigInt implementation to be in two's complement also? Most BigInt implementations use a separate sign I think, not sure if that's for performance reasons or merely convenience though.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 24, 2016 at 7:40 AM, Jordan Rose via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Oh, one more comment: I suggest naming the primary protocol something other than "Integer", which IMHO is a little close to "Int" for a beginner. "Integral" is a bit too ambiguous, but maybe "IntegerArithmetic" or "ArithmeticInteger"? Or to go with the representation thing, "BinaryInteger"? (Some of the requirements are at odds with a decimal-based implementation.)</div><div><br></div><div>Jordan</div><div><div class="h5"><div><br></div><br><div><blockquote type="cite"><div>On Jun 23, 2016, at 13:50, Jordan Rose <<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>> wrote:</div><br><div><div style="word-wrap:break-word">Hey, standard library folks. Glad we're doing this one. :-)<div><br></div><div>- I remain unconvinced that defining an Arithmetic that includes both exact and floating-point numbers is a good idea. All of the arguments from Swift 1 and 2 about why we didn't include this still seem relevant. To phrase it in generic programming terms, what algorithm would be generic over Arithmetic?</div><div><br></div><div><br></div><div>- What is Integer.init<T: FloatingPoint>(_:) supposed to do if the floating-point value is larger than the maximum representable integer? Smaller than the minimum? (As a special case, negative, when the integer type is unsigned?) Infinity? NaN?</div><div><br></div><div>- Integer.init<T: Integer>(_:) currently says "if it is representable". It should say something like "trapping if it is not representable".</div><div><br></div><div>- I find it odd that Integer.init(clamping:) privileges the bounds of fixed-width integers. I was going to suggest it should take a range to clamp to that <i>defaults</i> to the min and max, but that's not implementable for a BigInt.</div><div><br></div><div>- nthWord should count "from least-significant to most-significant" rather than "from the right".</div><div><br></div><div>- As mentioned before, it sounds like Integer requires a two's complement representation (if only so the result of nthWord can be interpreted correctly). That should probably be in the doc comment for the protocol.</div><div><br></div><div>- Why is bitWidth in bits but nthWord in words? (I know there's a good answer to this, but using them together seems like it will be common.)</div><div><br></div><div>- It's also probably worth calling out <i>even more explicitly</i> that bitWidth is a <i>representation</i> property, not a <i>value</i> property. That is, a BigInt with the value "1" could have a bitWidth of 1, 8, or 128.</div><div><br></div><div>- What does signBitIndex return if self is positive? I ask because it's just not in the doc comment, but thinking about the answer made it obvious that the correct return value for 0 is 0.</div><div><br></div><div>- For signed integers, does remainder(dividingBy:) have specified behavior for the sign of the result? See <a href="https://en.wikipedia.org/wiki/Modulo_operation" target="_blank">https://en.wikipedia.org/wiki/Modulo_operation</a>.</div><div><br></div><div><div>- I do think having Swift.abs(_:) and Integer.absoluteValue is confusing, but I don't know what to do about it.</div></div><div><br></div><div><br></div><div>- Why are bitwise operations limited to fixed-width integers? I see "The only difference is that because shifting left truncates the high bits of fixed-width integers, it is hard to define what a left shift would mean to an arbitrary-precision integer" further down, but I would just assume it wouldn't truncate (i.e. it would be a pure multiplication by two).</div><div><br></div><div>- Is there a requirement about left-shifting into the sign bit, for '<<' and for '&<<'?</div><div><div><br></div><div>- What is the ArithmeticOverflow type?</div><div><br></div><div>- When does the remainder operation overflow? (I just can't remember.)</div><div><br></div><div>- I feel a little weird having "someValue.and(mask)". Maybe bitwiseAnd or bitwiseAND to be more explicit?</div><div><br></div></div><div>- maskingShiftLeft/Right seem underspecified in their doc comments. Why can't the protocol requirement just assume the shift amount has already been masked, instead of performing the masking themselves? Is it because we won't be able to optimize that away?</div><div><br></div><div>I think that's about it. Great work, all!</div><div>Jordan</div></div></div></blockquote></div><br></div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>