@Override protected BigInteger absDiff(BigInteger actual, BigInteger other) { return actual.subtract(other).abs(); }
@Override protected BigInteger absDiff(BigInteger actual, BigInteger other) { return actual.subtract(other).abs(); }
@Override public String generate(String imageUri) { byte[] md5 = getMD5(imageUri.getBytes()); BigInteger bi = new BigInteger(md5).abs(); return bi.toString(RADIX); }
/** * Divide 2 numbers in half (for split algorithm) * * @param a number #1 * @param b number #2 * @return the midpoint of the 2 numbers */ public BigInteger split2(BigInteger a, BigInteger b) { return a.add(b).divide(BigInteger.valueOf(2)).abs(); }
public static boolean overflows(BigInteger value, int precision) { return value.abs().compareTo(bigIntegerTenToNth(precision)) >= 0; }
public static boolean overflows(BigInteger value, int precision) { return value.abs().compareTo(bigIntegerTenToNth(precision)) >= 0; }
static double bigToDouble(BigInteger x) { BigInteger absX = x.abs(); int exponent = absX.bitLength() - 1;
private int ensureExactRounding(final BigDecimal initialValue, final int extraPrecision) { String significand = initialValue.unscaledValue().abs().toString(); int undiscardedPrecision = Math.max(0, significand.length() - extraPrecision); for (int i = undiscardedPrecision; i < significand.length(); i++) { if (significand.charAt(i) != '0') { throw new NumberFormatException("Conversion to Decimal128 would require inexact rounding of " + initialValue); } } return undiscardedPrecision; }
private static String getMD5Hex(String str){ byte[] data = getMD5(str.getBytes()); BigInteger bi = new BigInteger(data).abs(); String result = bi.toString(36); return result; }
/** * Validates the specified prospective start value, min value, max value and * increment relative to each other, since each of their respective * validities are contingent on the values of the other parameters. * * @param value the prospective start value * @param minValue the prospective min value * @param maxValue the prospective max value * @param increment the prospective increment */ private static boolean isValid(long value, long minValue, long maxValue, long increment) { return minValue <= value && maxValue >= value && maxValue > minValue && increment != 0 && // Math.abs(increment) < maxValue - minValue // use BigInteger to avoid overflows when maxValue and minValue // are really big BigInteger.valueOf(increment).abs().compareTo( BigInteger.valueOf(maxValue).subtract(BigInteger.valueOf(minValue))) < 0; }
public static BigInteger md5hash(ByteBuffer data) { byte[] result = FBUtilities.hash(data); BigInteger hash = new BigInteger(result); return hash.abs(); }
protected Number absImpl(Number number) { return toBigInteger(number).abs(); }
static double bigToDouble(BigInteger x) { BigInteger absX = x.abs(); int exponent = absX.bitLength() - 1;
public static Slice pack(BigInteger unscaledValue, Slice result) { pack(0, 0, false, result); byte[] bytes = unscaledValue.abs().toByteArray(); if (bytes.length > UNSCALED_DECIMAL_128_SLICE_LENGTH || (bytes.length == UNSCALED_DECIMAL_128_SLICE_LENGTH && (bytes[0] & SIGN_BYTE_MASK) != 0)) { throwOverflowException(); } // convert to little-endian order reverse(bytes); result.setBytes(0, bytes); if (unscaledValue.signum() < 0) { setNegative(result, true); } throwIfOverflows(result); return result; }
public static Slice pack(BigInteger unscaledValue, Slice result) { pack(0, 0, false, result); byte[] bytes = unscaledValue.abs().toByteArray(); if (bytes.length > UNSCALED_DECIMAL_128_SLICE_LENGTH || (bytes.length == UNSCALED_DECIMAL_128_SLICE_LENGTH && (bytes[0] & SIGN_BYTE_MASK) != 0)) { throwOverflowException(); } // convert to little-endian order reverse(bytes); result.setBytes(0, bytes); if (unscaledValue.signum() < 0) { setNegative(result, true); } throwIfOverflows(result); return result; }
@Test public void testMultiToken() { int h1 = tokenManager.regionOffset("vijay"); int h2 = tokenManager.regionOffset("vijay2"); BigInteger t1 = tokenManager.initialToken(100, 10, h1); BigInteger t2 = tokenManager.initialToken(100, 10, h2); BigInteger tokendistance = t1.subtract(t2).abs(); int hashDiffrence = h1 - h2; assertEquals(new BigInteger("" + hashDiffrence).abs(), tokendistance); BigInteger t3 = tokenManager.initialToken(100, 99, h1); BigInteger t4 = tokenManager.initialToken(100, 99, h2); tokendistance = t3.subtract(t4).abs(); assertEquals(new BigInteger("" + hashDiffrence).abs(), tokendistance); }
@Test public void testMultiToken() { int h1 = tokenManager.regionOffset("vijay"); int h2 = tokenManager.regionOffset("vijay2"); BigInteger t1 = tokenManager.initialToken(100, 10, h1); BigInteger t2 = tokenManager.initialToken(100, 10, h2); BigInteger tokendistance = t1.subtract(t2).abs(); int hashDiffrence = h1 - h2; assertEquals(new BigInteger("" + hashDiffrence).abs(), tokendistance); BigInteger t3 = tokenManager.initialToken(100, 99, h1); BigInteger t4 = tokenManager.initialToken(100, 99, h2); tokendistance = t3.subtract(t4).abs(); assertEquals(new BigInteger("" + hashDiffrence).abs(), tokendistance); } }