/** Returns the value of this {@code UnsignedInteger} as a {@code long}. */ @Override public long longValue() { return toLong(value); }
@Override public long padToLong() { return UnsignedInts.toLong(hash); }
/** * Returns dividend / divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * <p><b>Java 8 users:</b> use {@link Integer#divideUnsigned(int, int)} instead. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int divide(int dividend, int divisor) { return (int) (toLong(dividend) / toLong(divisor)); }
/** * Returns dividend % divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * <p><b>Java 8 users:</b> use {@link Integer#remainderUnsigned(int, int)} instead. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int remainder(int dividend, int divisor) { return (int) (toLong(dividend) % toLong(divisor)); }
/** Returns the value of this {@code UnsignedInteger} as a {@code long}. */ @Override public long longValue() { return toLong(value); }
/** * Returns dividend % divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * <p><b>Java 8 users:</b> use {@link Integer#remainderUnsigned(int, int)} instead. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int remainder(int dividend, int divisor) { return (int) (toLong(dividend) % toLong(divisor)); }
@Override public long padToLong() { return UnsignedInts.toLong(hash); }
/** * Returns dividend / divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * <p><b>Java 8 users:</b> use {@link Integer#divideUnsigned(int, int)} instead. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int divide(int dividend, int divisor) { return (int) (toLong(dividend) / toLong(divisor)); }
/** * Returns dividend / divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * <p><b>Java 8 users:</b> use {@link Integer#divideUnsigned(int, int)} instead. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int divide(int dividend, int divisor) { return (int) (toLong(dividend) / toLong(divisor)); }
/** Returns the value of this {@code UnsignedInteger} as a {@code long}. */ @Override public long longValue() { return toLong(value); }
/** * Returns dividend % divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * <p><b>Java 8 users:</b> use {@link Integer#remainderUnsigned(int, int)} instead. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int remainder(int dividend, int divisor) { return (int) (toLong(dividend) % toLong(divisor)); }
@Override public long padToLong() { return UnsignedInts.toLong(hash); }
private void updateMax(int time) { long max; do { max = this.max.get(); if (max >= 0 && ((int) max) >= time) { return; } } while (!this.max.compareAndSet(max, UnsignedInts.toLong(time))); }
private void updateMin(int time) { long min; do { min = this.min.get(); if (min >= 0 && ((int) min) <= time) { return; } } while (!this.min.compareAndSet(min, UnsignedInts.toLong(time))); }
public void testToLong() { for (long a : UNSIGNED_INTS) { assertEquals(a, UnsignedInts.toLong((int) a)); } }
public void testCheckedCast() { for (long value : UNSIGNED_INTS) { assertEquals(value, UnsignedInts.toLong(UnsignedInts.checkedCast(value))); } assertCastFails(1L << 32); assertCastFails(-1L); assertCastFails(Long.MAX_VALUE); assertCastFails(Long.MIN_VALUE); }
public void testSaturatedCast() { for (long value : UNSIGNED_INTS) { assertEquals(value, UnsignedInts.toLong(UnsignedInts.saturatedCast(value))); } assertEquals(GREATEST, UnsignedInts.saturatedCast(1L << 32)); assertEquals(LEAST, UnsignedInts.saturatedCast(-1L)); assertEquals(GREATEST, UnsignedInts.saturatedCast(Long.MAX_VALUE)); assertEquals(LEAST, UnsignedInts.saturatedCast(Long.MIN_VALUE)); }
/** * Returns the value of this {@code UnsignedInteger} as a {@code long}. */ @Override public long longValue() { return toLong(value); }
/** * Returns dividend / divisor, where the dividend and divisor are treated as unsigned 32-bit * quantities. * * @param dividend the dividend (numerator) * @param divisor the divisor (denominator) * @throws ArithmeticException if divisor is 0 */ public static int divide(int dividend, int divisor) { return (int) (toLong(dividend) / toLong(divisor)); }
/** * Returns the value of this {@code UnsignedInteger} as a {@code long}. */ @Override public long longValue() { return toLong(value); }