> On Jun 26, 2016, at 6:38 PM, Károly Lőrentey via swift-evolution 
> <[email protected]> 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
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to