Negative modulo

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Conventional implementation
function mmod(n, m) {
	return ((m % n) + n) % n;
}
ready
Optimised
function mmod(n, m) {
  const result = m % n;
  return result >= 0 ? result : result + n;
}
ready
Bitwise operations
function mmod(n, m) {
  const result = m % n;
  return result >= 0 ? result : (result + n) | 0;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.