code: public static int Mod(int x, int m) {
          if (m < 0) m = -m;
          int r = x % m;
          return r < 0 ? r + m : r;
      }
docs: Gets the proper modulus operation.
  
  @param x Integer.
  @param m Modulo.
  @return Modulus.