In Ceylon, the result of remainder() takes the sign of the dividend:
-10 % 7 = -3
An alternate interpretation is sometimes useful, where the result is always positive:
-10 mod 7 = 4
For reference, Java's BigInteger offers both remainder and mod.
For completeness and consistence with Whole, it may make sense to add Integral.modulo. Description/possible implementation:
if (!modulus.positive) {
throw AssertionError("modulus must be positive");
}
return let (result = remainder(modulus))
if (result.negative)
then result + modulus
else result;
In Ceylon, the result of
remainder()
takes the sign of the dividend:An alternate interpretation is sometimes useful, where the result is always positive:
For reference, Java's
BigInteger
offers both remainder and mod.For completeness and consistence with
Whole
, it may make sense to addIntegral.modulo
. Description/possible implementation: