@Override public int compareTo(final BsonTimestamp ts) { return UnsignedLongs.compare(value, ts.value); }
private static long remainder(final long dividend, final long divisor) { if (divisor < 0) { // i.e., divisor >= 2^63: if (compare(dividend, divisor) < 0) { return dividend; // dividend < divisor } else { return dividend - divisor; // dividend >= divisor } } // Optimization - use signed modulus if dividend < 2^63 if (dividend >= 0) { return dividend % divisor; } // Otherwise, approximate the quotient, check, and correct if necessary. Our approximation is // guaranteed to be either exact or one less than the correct value. This follows from the fact // that floor(floor(x)/i) == floor(x/i) for any real x and integer i != 0. The proof is not // quite trivial. long quotient = ((dividend >>> 1) / divisor) << 1; long rem = dividend - quotient * divisor; return rem - (compare(rem, divisor) >= 0 ? divisor : 0); }
private static long divide(final long dividend, final long divisor) { if (divisor < 0) { // i.e., divisor >= 2^63: if (compare(dividend, divisor) < 0) { return 0; // dividend < divisor } else { return 1; // dividend >= divisor } } // Optimization - use signed division if dividend < 2^63 if (dividend >= 0) { return dividend / divisor; } // Otherwise, approximate the quotient, check, and correct if necessary. Our approximation is // guaranteed to be either exact or one less than the correct value. This follows from fact that // floor(floor(x)/i) == floor(x/i) for any real x and integer i != 0. The proof is not quite // trivial. long quotient = ((dividend >>> 1) / divisor) << 1; long rem = dividend - quotient * divisor; return quotient + (compare(rem, divisor) >= 0 ? 1 : 0); }