in reply to Re^4: Best way to make sure a number is an even multiple of another?
in thread Best way to make sure a number is an even multiple of another?
The modulo operator works as I'd expect as long as you don't use integer; as soon as you do, you are at the mercy of your C implementation, which I believe is likely to vary between machines.
On this Linux machine, for example:
zen% perl -le 'print -1 % 3' 2 zen% perl -Minteger -le 'print -1 % 3' -1 zen%
If you're happy to rely on it, the original request to get the least multiple of $m >= $n can be satisfied by: $n + ((-$n) % $m).
Hugo
|
|---|