code: protected static final int floorDivide(int numerator, int denominator, int[] remainder) {
          if (numerator >= 0) {
              remainder[0] = numerator % denominator;
              return numerator / denominator;
          }
          int quotient = ((numerator + 1) / denominator) - 1;
          remainder[0] = numerator - (quotient * denominator);
          return quotient;
      }
docs: Divide two integers, returning the floor of the quotient, and
  the modulus remainder.
  <p>
  Unlike the built-in division, this is mathematically well-behaved.
  E.g., <code>-1/4</code> =&gt; 0 and <code>-1%4</code> =&gt; -1,
  but <code>floorDivide(-1,4)</code> =&gt; -1 with <code>remainder[0]</code> =&gt; 3.
  @param numerator the numerator
  @param denominator a divisor which must be &gt; 0
  @param remainder an array of at least one element in which the value
  <code>numerator mod denominator</code> is returned. Unlike <code>numerator
  % denominator</code>, this will always be non-negative.
  @return the floor of the quotient.