[swift-evolution] [Review] SE-0104: Protocol-oriented integers

Stephen Canon scanon at apple.com
Mon Jun 27 09:40:49 CDT 2016


> On Jun 26, 2016, at 6:38 PM, Károly Lőrentey via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I’m not sure if this has been mentioned yet, but the semantics of Integer operations also needs to be tied down. In particular, the expected behavior of the remainder operation (in all forms) when given a negative numerator and/or denumerator should be explicitly spelled out.

It may not be clearly documented in the stdlib (I haven’t checked), but it definitely *is* tied down.  Swift using truncating division, and remainder is defined to satisfy the usual definition of division:

	a = (a/b)*b + (a%b)

In particular, this means that if r = a%b, sign(r) == sign(a), and abs(r) < abs(b).

– Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160627/eee946a8/attachment.html>


More information about the swift-evolution mailing list