public static long floorMod(final long a, final long b) {

        if (b == 0L) {
            throw new IllegalArgumentException("denominator must be different from 0");
        }

        final long m = a % b;
        if ((a ^ b) >= 0L || m == 0L) {
            // a an b have same sign, or division is exact
            return m;
        } else {
            // a and b have opposite signs and division is not exact
            return b + m;
        }

    }
Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0.
<p>
This methods returns the same value as integer division when
a and b are same signs, but returns a different value when
they are opposite (i.e. q is negative).
</p>
@param a dividend
@param b divisor
@return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0
@exception IllegalArgumentException if b == 0
@see #floorMod(long, long)
@since 3.4
commons/src/main/java/com/navercorp/pinpoint/common/util/MathUtils.java