Could you specify the expected behavior when base
is negative? For example, in
// Here if base is 0, 1 or -1, return true iff self equals base.
if base.magnitude <= 1 { return self == base }
This will return false
when self == 1
and base == -1
...
Also, quotientAndRemainder
's documentation says:
A tuple containing the quotient and remainder of this value divided by
rhs
. The remainder has the same sign asrhs
.
But that doesn't seem to be the case in practice.
$ echo 'print((10 as Int).quotientAndRemainder(dividingBy: -3))' | xcrun swift
(quotient: -3, remainder: 1)
That makes it unclear what the later code using quotientAndRemainder
is trying to do.
(EDIT: I've filed [SR-13471] Mismatch between behavior of quotientAndRemainder and docs · Issue #55913 · apple/swift · GitHub for quotientAndRemainder
.)