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

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

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

BigInteger.longValueExact介绍

暂无

代码示例

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

private static long bigIntegerDecimalToGenericIntegerType(BigInteger bigInteger, int sourceScale, long minValue, long maxValue)
{
  BigDecimal bigDecimal = new BigDecimal(bigInteger, sourceScale);
  BigInteger unscaledValue = bigDecimal.setScale(0, FLOOR).unscaledValue();
  if (unscaledValue.compareTo(BigInteger.valueOf(maxValue)) > 0) {
    return maxValue;
  }
  if (unscaledValue.compareTo(BigInteger.valueOf(minValue)) < 0) {
    return minValue;
  }
  return unscaledValue.longValueExact();
}

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

public static long encodeShortScaledValue(BigDecimal value, int scale)
{
  checkArgument(scale >= 0);
  return value.setScale(scale, UNNECESSARY).unscaledValue().longValueExact();
}

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

public static long encodeShortScaledValue(BigDecimal value, int scale)
{
  checkArgument(scale >= 0);
  return value.setScale(scale, UNNECESSARY).unscaledValue().longValueExact();
}

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

public void setV(Object v) {
  if (v instanceof String) {
    this.v = Numeric.toBigInt((String) v).longValueExact();
  } else if (v instanceof Integer) {
    this.v = ((Integer) v).longValue();
  } else {
    this.v = (Long) v;
  }
}

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

@UsedByGeneratedCode
public static long shortDecimalToShortDecimal(long value, int sourcePrecision, int sourceScale, int resultPrecision, int resultScale)
{
  return bigintToBigintFloorSaturatedCast(BigInteger.valueOf(value), sourceScale, resultPrecision, resultScale).longValueExact();
}

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

@UsedByGeneratedCode
public static long genericIntegerTypeToShortDecimal(long value, int resultPrecision, int resultScale)
{
  return bigDecimalToBigintFloorSaturatedCast(BigDecimal.valueOf(value), resultPrecision, resultScale).longValueExact();
}

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

private static Long shortDecimal(String value)
{
  return new BigDecimal(value).unscaledValue().longValueExact();
}

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

public static Long shortDecimal(String value)
{
  return new BigDecimal(value).unscaledValue().longValueExact();
}

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

@UsedByGeneratedCode
public static long longDecimalToShortDecimal(Slice value, int sourcePrecision, int sourceScale, int resultPrecision, int resultScale)
{
  return bigintToBigintFloorSaturatedCast(decodeUnscaledValue(value), sourceScale, resultPrecision, resultScale).longValueExact();
}

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

public static void outputShortDecimal(DecimalType type, LongDecimalWithOverflowAndLongState state, BlockBuilder out)
{
  if (state.getLong() == 0) {
    out.appendNull();
  }
  else {
    writeShortDecimal(out, average(state, type).unscaledValue().longValueExact());
  }
}

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

public static Long calculateLiteralValue(
    String calculation,
    Map<String, Long> inputs)
{
  try {
    ParserRuleContext tree = parseTypeCalculation(calculation);
    CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs);
    BigInteger result = visitor.visit(tree);
    return result.longValueExact();
  }
  catch (StackOverflowError e) {
    throw new ParsingException("Type calculation is too large (stack overflow while parsing)");
  }
}

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

private void assertAddReturnOverflow(BigInteger left, BigInteger right)
{
  Slice result = unscaledDecimal();
  long overflow = addWithOverflow(unscaledDecimal(left), unscaledDecimal(right), result);
  BigInteger actual = unscaledDecimalToBigInteger(result);
  BigInteger expected = left.add(right).remainder(TWO.pow(UnscaledDecimal128Arithmetic.UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 1));
  BigInteger expectedOverflow = left.add(right).divide(TWO.pow(UnscaledDecimal128Arithmetic.UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 1));
  assertEquals(actual, expected);
  assertEquals(overflow, expectedOverflow.longValueExact());
}

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

boolean isSynced() throws Exception {
  EthSyncing ethSyncing = web3j.ethSyncing().send();
  if (ethSyncing.isSyncing()) {
    return false;
  } else {
    EthBlock ethBlock =
        web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send();
    long timestamp = ethBlock.getBlock().getTimestamp().longValueExact() * 1000;
    return System.currentTimeMillis() - syncThreshold < timestamp;
  }
}

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

} else {
  try {
    rec.put(i - 1, ((BigInteger) value).longValueExact());
  } catch (ArithmeticException ae) {

代码示例来源:origin: org.elasticsearch/elasticsearch

/** Return the long that {@code n} stores, or throws an exception if the
 *  stored value cannot be converted to a long that stores the exact same
 *  value. */
public static long toLongExact(Number n) {
  if (n instanceof Byte || n instanceof Short || n instanceof Integer
      || n instanceof Long) {
    return n.longValue();
  } else if (n instanceof Float || n instanceof Double) {
    double d = n.doubleValue();
    if (d != Math.round(d)) {
      throw new IllegalArgumentException(n + " is not an integer value");
    }
    return n.longValue();
  } else if (n instanceof BigDecimal) {
    return ((BigDecimal) n).toBigIntegerExact().longValueExact();
  } else if (n instanceof BigInteger) {
    return ((BigInteger) n).longValueExact();
  } else {
    throw new IllegalArgumentException("Cannot check whether [" + n + "] of class [" + n.getClass().getName()
        + "] is actually a long");
  }
}

代码示例来源:origin: io.prestosql/presto-jdbc

public static long encodeShortScaledValue(BigDecimal value, int scale)
{
  checkArgument(scale >= 0);
  return value.setScale(scale, UNNECESSARY).unscaledValue().longValueExact();
}

代码示例来源:origin: org.beryx/streamplify

protected static long count(int[] dimensions) {
    BigInteger bigCount = BigIntegerCartesianProduct.count(dimensions);
    if(bigCount.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) >= 0) throw new IllegalArgumentException("Dimensions too big: " + Arrays.toString(dimensions));
    return bigCount.longValueExact();
  }
}

代码示例来源:origin: NemProject/nem.core

private long getRawQuantity(final Quantity quantity) {
  return BigInteger.valueOf(this.amount.getNumMicroNem())
      .multiply(BigInteger.valueOf(quantity.getRaw()))
      .divide(BigInteger.valueOf(Amount.MICRONEMS_IN_NEM))
      .longValueExact();
}

代码示例来源:origin: io.prestosql/presto-main

@UsedByGeneratedCode
public static long genericIntegerTypeToShortDecimal(long value, int resultPrecision, int resultScale)
{
  return bigDecimalToBigintFloorSaturatedCast(BigDecimal.valueOf(value), resultPrecision, resultScale).longValueExact();
}

代码示例来源:origin: Unidata/thredds

@Test
public void testUnsignedLongToBigInt() {
 Assert.assertEquals("The long round-trips as expected.",
     Long.MAX_VALUE, DataType.unsignedLongToBigInt(Long.MAX_VALUE).longValueExact());
 BigInteger overflowAsBigInt = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
 Assert.assertEquals(new BigInteger("9223372036854775808"), overflowAsBigInt);
 long overflowAsLong = overflowAsBigInt.longValue();
 Assert.assertEquals(-9223372036854775808L, overflowAsLong);
 Assert.assertEquals("Interpret signed long as unsigned long",
     overflowAsBigInt, DataType.unsignedLongToBigInt(overflowAsLong));
}

相关文章