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

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

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

BigInteger.remainder介绍

[英]Returns a BigInteger whose value is this % divisor. Regarding signs this methods has the same behavior as the % operator on ints: the sign of the remainder is the same as the sign of this.
[中]返回一个BigInteger,其值为该%除数。关于符号,此方法与ints上的%运算符具有相同的行为:余数的符号与此的符号相同。

代码示例

代码示例来源:origin: kiegroup/optaplanner

@Override
public boolean contains(BigInteger value) {
  if (value == null || value.compareTo(from) < 0 || value.compareTo(to) >= 0) {
    return false;
  }
  return value.subtract(from).remainder(incrementUnit).compareTo(BigInteger.ZERO) == 0;
}

代码示例来源:origin: aa112901/remusic

public static void main3(String[] args) {
  String key = "7b104953fb112826";
  String pubKey = "010001";
  String m = "157794750267131502212476817800345498121872783333389747424011531025366277535262539913701806290766479189477533597854989606803194253978660329941980786072432806427833685472618792592200595694346872951301770580765135349259590167490536138082469680638514416594216629258349130257685001248172188325316586707301643237607";
  try {
    String k = reverse(key);
    String keyTo16 = toHex(k, "GBK");
    // System.out.println(new BigInteger(keyTo16, 16));
    // new BigInteger(keyTo16, 16) 字符串转为16进制数字,
    // pow(Integer.valueOf(pubKey, 16)) 得到次方的值
    //remainder 取余数
    String c = (new BigInteger(keyTo16, 16).pow(Integer.valueOf(pubKey, 16))).remainder(new BigInteger(m)) + "";
    //转为16进制表示
    System.out.println(new BigInteger(c).toString(16));
  } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: aa112901/remusic

public static String rsaEncode(String key) {
  String pubKey = "010001";
  String m = "157794750267131502212476817800345498121872783333389747424011531025366277535262539913701806290766479189477533597854989606803194253978660329941980786072432806427833685472618792592200595694346872951301770580765135349259590167490536138082469680638514416594216629258349130257685001248172188325316586707301643237607";
  try {
    String k = reverse(key);
    String keyTo16 = toHex(k, "GBK");
    // System.out.println(new BigInteger(keyTo16, 16));
    // new BigInteger(keyTo16, 16) 字符串转为16进制数字,
    // pow(Integer.valueOf(pubKey, 16)) 得到次方的值
    //remainder 取余数
    String c = (new BigInteger(keyTo16, 16).pow(Integer.valueOf(pubKey, 16))).remainder(new BigInteger(m)) + "";
    //转为16进制表示
    return (new BigInteger(c).toString(16));
  } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
  }
  return "-1";
}

代码示例来源:origin: kiegroup/optaplanner

/**
 * @param from never null, inclusive minimum
 * @param to never null, exclusive maximum, {@code >= from}
 * @param incrementUnit never null, {@code > 0}
 */
public BigIntegerValueRange(BigInteger from, BigInteger to, BigInteger incrementUnit) {
  this.from = from;
  this.to = to;
  this.incrementUnit = incrementUnit;
  if (to.compareTo(from) < 0) {
    throw new IllegalArgumentException("The " + getClass().getSimpleName()
        + " cannot have a from (" + from + ") which is strictly higher than its to (" + to + ").");
  }
  if (incrementUnit.compareTo(BigInteger.ZERO) <= 0) {
    throw new IllegalArgumentException("The " + getClass().getSimpleName()
        + " must have strictly positive incrementUnit (" + incrementUnit + ").");
  }
  if (!to.subtract(from).remainder(incrementUnit).equals(BigInteger.ZERO)) {
    throw new IllegalArgumentException("The " + getClass().getSimpleName()
        + "'s incrementUnit (" + incrementUnit
        + ") must fit an integer number of times between from (" + from + ") and to (" + to + ").");
  }
}

代码示例来源:origin: kiegroup/optaplanner

if (!to.unscaledValue().subtract(from.unscaledValue()).remainder(incrementUnit.unscaledValue())
    .equals(BigInteger.ZERO)) {
  throw new IllegalArgumentException("The " + getClass().getSimpleName()

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

fastBigIntegerValueUnscaled(
     fastSignum, fast0, fast1, fast2);
 return bigInteger.remainder(BIG_INTEGER_UNSIGNED_INT_MAX_VALUE).intValue();
} else {
   fastBigIntegerValueUnscaled(
     fastSignum, result0, result1, result2);
 return bigInteger.remainder(BIG_INTEGER_UNSIGNED_INT_MAX_VALUE).intValue();

代码示例来源:origin: konsoletyper/teavm

break;
case UNNECESSARY:
  if (mantissa.remainder(rounding).equals(BigInteger.ZERO)) {
    throw new TArithmeticException(TString.wrap("Can't avoid rounding"));
  if (mantissa.remainder(rounding).equals(signedRounding.divide(BigInteger.valueOf(2)))) {
    mantissa = mantissa.divide(rounding).multiply(rounding);
  } else {
  if (mantissa.remainder(rounding).equals(signedRounding.divide(BigInteger.valueOf(2)))) {
    mantissa = mantissa.divide(rounding).multiply(rounding).add(signedRounding);
  } else {
  if (mantissa.remainder(rounding).equals(signedRounding.divide(BigInteger.valueOf(2)))) {
    mantissa = mantissa.divide(rounding).multiply(rounding);
    if (!mantissa.divide(rounding).remainder(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) {
      mantissa = mantissa.add(signedRounding);

代码示例来源:origin: kingthy/TVRemoteIME

r = BigInteger.ZERO.setBit(KEY_LENGTH_WORDS * 32);
rr = r.modPow(BigInteger.valueOf(2), n);
rem = n.remainder(r32);
n0inv = rem.modInverse(r32);

代码示例来源: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: google/guava

@GwtIncompatible // TODO
@AndroidIncompatible // slow
public void testDivNonZeroExact() {
 boolean isAndroid = System.getProperties().getProperty("java.runtime.name").contains("Android");
 for (BigInteger p : NONZERO_BIGINTEGER_CANDIDATES) {
  for (BigInteger q : NONZERO_BIGINTEGER_CANDIDATES) {
   if (isAndroid && p.equals(BAD_FOR_ANDROID_P) && q.equals(BAD_FOR_ANDROID_Q)) {
    // https://code.google.com/p/android/issues/detail?id=196555
    continue;
   }
   if (isAndroid && p.equals(BAD_FOR_GINGERBREAD_P) && q.equals(BAD_FOR_GINGERBREAD_Q)) {
    // Works fine under Marshmallow, so I haven't filed a bug.
    continue;
   }
   boolean dividesEvenly = p.remainder(q).equals(ZERO);
   try {
    BigInteger quotient = BigIntegerMath.divide(p, q, UNNECESSARY);
    BigInteger undone = quotient.multiply(q);
    if (!p.equals(undone)) {
     failFormat("expected %s.multiply(%s) = %s; got %s", quotient, q, p, undone);
    }
    assertTrue(dividesEvenly);
   } catch (ArithmeticException e) {
    assertFalse(dividesEvenly);
   }
  }
 }
}

代码示例来源:origin: org.apache.commons/commons-math3

BigInteger den = fraction.getDenominator();
BigInteger whole = num.divide(den);
num = num.remainder(den);

代码示例来源:origin: spring-projects/spring-framework

BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class);
BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class);
return new TypedValue(leftBigInteger.remainder(rightBigInteger));

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

fastBigIntegerValueUnscaled(
     fastSignum, fast0, fast1, fast2);
 return bigInteger.remainder(BIG_INTEGER_UNSIGNED_SHORT_MAX_VALUE).shortValue();
} else {
   fastBigIntegerValueUnscaled(
     fastSignum, result0, result1, result2);
 return bigInteger.remainder(BIG_INTEGER_UNSIGNED_SHORT_MAX_VALUE).shortValue();

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

fastBigIntegerValueUnscaled(
     fastSignum, fast0, fast1, fast2);
 return bigInteger.remainder(BIG_INTEGER_UNSIGNED_BYTE_MAX_VALUE).byteValue();
} else {
   fastBigIntegerValueUnscaled(
     fastSignum, result0, result1, result2);
 return bigInteger.remainder(BIG_INTEGER_UNSIGNED_BYTE_MAX_VALUE).byteValue();

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

fastBigIntegerValueUnscaled(
    fastSignum, fast0, fast1, fast2);
return bigInteger.remainder(BIG_INTEGER_UNSIGNED_LONG_MAX_VALUE).longValue();
  fastBigIntegerValueUnscaled(
    fastSignum, result0, result1, result2);
return bigInteger.remainder(BIG_INTEGER_UNSIGNED_LONG_MAX_VALUE).longValue();

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

public void testMod() {
 for (long a : TEST_LONGS) {
  for (long b : TEST_LONGS) {
   if (b != 0) {
    UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a);
    UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b);
    long expected =
      aUnsigned.bigIntegerValue().remainder(bUnsigned.bigIntegerValue()).longValue();
    UnsignedLong unsignedRem = aUnsigned.mod(bUnsigned);
    assertEquals(expected, unsignedRem.longValue());
   }
  }
 }
}

代码示例来源:origin: org.springframework/spring-expression

BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class);
BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class);
return new TypedValue(leftBigInteger.remainder(rightBigInteger));

代码示例来源:origin: camunda/camunda-bpm-platform

public static final Number mod(TypeConverter converter, Object o1, Object o2) {
  if (o1 == null && o2 == null) {
    return LONG_ZERO;
  }
  if (isBigDecimalOrFloatOrDoubleOrDotEe(o1) || isBigDecimalOrFloatOrDoubleOrDotEe(o2)) {
    return converter.convert(o1, Double.class) % converter.convert(o2, Double.class);
  }
  if (o1 instanceof BigInteger || o2 instanceof BigInteger) {
    return converter.convert(o1, BigInteger.class).remainder(converter.convert(o2, BigInteger.class));
  }
  return converter.convert(o1, Long.class) % converter.convert(o2, Long.class);
}

代码示例来源:origin: camunda/camunda-bpm-platform

public static final Number mod(TypeConverter converter, Object o1, Object o2) {
  if (o1 == null && o2 == null) {
    return LONG_ZERO;
  }
  if (isBigDecimalOrFloatOrDoubleOrDotEe(o1) || isBigDecimalOrFloatOrDoubleOrDotEe(o2)) {
    return converter.convert(o1, Double.class) % converter.convert(o2, Double.class);
  }
  if (o1 instanceof BigInteger || o2 instanceof BigInteger) {
    return converter.convert(o1, BigInteger.class).remainder(converter.convert(o2, BigInteger.class));
  }
  return converter.convert(o1, Long.class) % converter.convert(o2, Long.class);
}

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

public static Object remainder(Object v1, Object v2)
{
  int type = getNumericType(v1, v2);
  switch(type) {
  case BIGDEC:
  case BIGINT:
    return bigIntValue(v1).remainder(bigIntValue(v2));
  default:
    return newInteger(type, longValue(v1) % longValue(v2));
  }
}

相关文章