java.math.BigInteger.abs()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中java.math.BigInteger.abs()方法的一些代码示例,展示了BigInteger.abs()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.abs()方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:abs

BigInteger.abs介绍

[英]Returns a BigInteger whose value is the absolute value of this.
[中]返回一个BigInteger,其值为该值的绝对值。

代码示例

代码示例来源:origin: org.assertj/assertj-core

@Override
protected BigInteger absDiff(BigInteger actual, BigInteger other) {
 return actual.subtract(other).abs();
}

代码示例来源:origin: joel-costigliola/assertj-core

@Override
protected BigInteger absDiff(BigInteger actual, BigInteger other) {
 return actual.subtract(other).abs();
}

代码示例来源:origin: nostra13/Android-Universal-Image-Loader

@Override
public String generate(String imageUri) {
  byte[] md5 = getMD5(imageUri.getBytes());
  BigInteger bi = new BigInteger(md5).abs();
  return bi.toString(RADIX);
}

代码示例来源:origin: apache/hbase

/**
 * 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();
}

代码示例来源:origin: deeplearning4j/nd4j

/**
 * Absolute value.
 *
 * @return The absolute (non-negative) value of this.
 */
public Rational abs() {
  return (new Rational(a.abs(), b.abs()));
}

代码示例来源:origin: prestodb/presto

public static boolean overflows(BigInteger value, int precision)
{
  return value.abs().compareTo(bigIntegerTenToNth(precision)) >= 0;
}

代码示例来源:origin: prestodb/presto

public static boolean overflows(BigInteger value, int precision)
{
  return value.abs().compareTo(bigIntegerTenToNth(precision)) >= 0;
}

代码示例来源:origin: google/guava

static double bigToDouble(BigInteger x) {
 BigInteger absX = x.abs();
 int exponent = absX.bitLength() - 1;

代码示例来源:origin: org.mongodb/mongo-java-driver

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;
}

代码示例来源:origin: androidquery/androidquery

private static String getMD5Hex(String str){
  byte[] data = getMD5(str.getBytes());
  
  BigInteger bi = new BigInteger(data).abs();

  String result = bi.toString(36);
  return result;
}

代码示例来源:origin: com.h2database/h2

/**
 * 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;
}

代码示例来源:origin: tjake/Solandra

public static BigInteger md5hash(ByteBuffer data)
{
  byte[] result = FBUtilities.hash(data);
  BigInteger hash = new BigInteger(result);
  return hash.abs();
}

代码示例来源:origin: org.codehaus.groovy/groovy

protected Number absImpl(Number number) {
  return toBigInteger(number).abs();
}

代码示例来源:origin: prestodb/presto

static double bigToDouble(BigInteger x) {
 BigInteger absX = x.abs();
 int exponent = absX.bitLength() - 1;

代码示例来源:origin: ethereum/ethereumj

public DataWord sMod(DataWord word) {
  if (word.isZero()) {
    return ZERO;
  }
  BigInteger result = sValue().abs().mod(word.sValue().abs());
  result = (sValue().signum() == -1) ? result.negate() : result;
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

代码示例来源:origin: prestodb/presto

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;
}

代码示例来源:origin: prestodb/presto

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;
}

代码示例来源:origin: Netflix/Priam

@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);
}

代码示例来源:origin: Netflix/Priam

@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);
  }
}

代码示例来源:origin: prestodb/presto

BigInteger expectedRemainder = expectedQuotientAndRemainder[1];
boolean overflowIsExpected = expectedQuotient.abs().compareTo(bigIntegerTenToNth(38)) >= 0 || expectedRemainder.abs().compareTo(bigIntegerTenToNth(38)) >= 0;

相关文章