本文整理汇总了Java中java.math.BigInteger.remainder方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.remainder方法的具体用法?Java BigInteger.remainder怎么用?Java BigInteger.remainder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.remainder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBinary
import java.math.BigInteger; //导入方法依赖的package包/类
String getBinary(BigDecimal fl) throws Exception{
BigInteger fi = fl.toBigInteger();
BigInteger rm;
String response="";
while(fi.compareTo(toDeno)>=0){
rm=fi.remainder(toDeno);
if(rm.compareTo(BigInteger.ZERO)==0)
response='0'+","+response;
else
response=rm.toString()+","+response;
fi=fi.subtract(rm).divide(toDeno);
}
response = fi.toString()+","+response;
if(response.endsWith(","))
response=response.substring(0,response.length()-1);
return response;
}
示例2: getBinary
import java.math.BigInteger; //导入方法依赖的package包/类
String getBinary(BigDecimal fl) throws Exception{
BigInteger fi = fl.toBigInteger();
BigInteger rm;
String response="";
while(fi.compareTo(tWO)>=0){
rm=fi.remainder(tWO);
if(rm.compareTo(BigInteger.ZERO)==0)
response='0'+response;
else
response='1'+response;
fi=fi.subtract(rm).divide(tWO);
}
int precisionCorrection=(response.length()-response.length()%10)/10;
localMC=new MathContext(jc.MC.getPrecision()+precisionCorrection,jc.MC.getRoundingMode());
return fi.toString()+response;
}
示例3: validateDHPublicKey
import java.math.BigInteger; //导入方法依赖的package包/类
private static void validateDHPublicKey(BigInteger p,
BigInteger g, BigInteger y) throws InvalidKeyException {
// For better interoperability, the interval is limited to [2, p-2].
BigInteger leftOpen = BigInteger.ONE;
BigInteger rightOpen = p.subtract(BigInteger.ONE);
if (y.compareTo(leftOpen) <= 0) {
throw new InvalidKeyException(
"Diffie-Hellman public key is too small");
}
if (y.compareTo(rightOpen) >= 0) {
throw new InvalidKeyException(
"Diffie-Hellman public key is too large");
}
// y^q mod p == 1?
// Unable to perform this check as q is unknown in this circumstance.
// p is expected to be prime. However, it is too expensive to check
// that p is prime. Instead, in order to mitigate the impact of
// non-prime values, we check that y is not a factor of p.
BigInteger r = p.remainder(y);
if (r.equals(BigInteger.ZERO)) {
throw new InvalidKeyException("Invalid Diffie-Hellman parameters");
}
}
示例4: setYear
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* <p>Set year of XSD <code>dateTime</code> year field.</p>
*
* <p>Unset this field by invoking the setter with a parameter value of
* {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
*
* <p>Note: if the absolute value of the <code>year</code> parameter
* is less than 10^9, the eon component of the XSD year field is set to
* <code>null</code> by this method.</p>
*
* @param year value constraints are summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
* If year is {@link DatatypeConstants#FIELD_UNDEFINED}, then eon is set to <code>null</code>.
*/
public final void setYear(int year) {
if (year == DatatypeConstants.FIELD_UNDEFINED) {
this.year = DatatypeConstants.FIELD_UNDEFINED;
this.eon = null;
}
else if (Math.abs(year) < BILLION_I) {
this.year = year;
this.eon = null;
} else {
BigInteger theYear = BigInteger.valueOf((long) year);
BigInteger remainder = theYear.remainder(BILLION_B);
this.year = remainder.intValue();
setEon(theYear.subtract(remainder));
}
}
示例5: setYear
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* <p>Set year of XSD <code>dateTime</code> year field.</p>
*
* <p>Unset this field by invoking the setter with a parameter value of
* {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
*
* <p>Note: if the absolute value of the <code>year</code> parameter
* is less than 10^9, the eon component of the XSD year field is set to
* <code>null</code> by this method.</p>
*
* @param year value constraints are summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
* If year is {@link DatatypeConstants#FIELD_UNDEFINED}, then eon is set to <code>null</code>.
*/
public void setYear(int year) {
if (year == DatatypeConstants.FIELD_UNDEFINED) {
this.year = DatatypeConstants.FIELD_UNDEFINED;
this.eon = null;
} else if (Math.abs(year) < BILLION.intValue()) {
this.year = year;
this.eon = null;
} else {
BigInteger theYear = BigInteger.valueOf((long) year);
BigInteger remainder = theYear.remainder(BILLION);
this.year = remainder.intValue();
setEon(theYear.subtract(remainder));
}
}
示例6: mod
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger mod(BigInteger arg0, BigInteger arg1) {
return arg0.remainder(arg1);
}
示例7: doBigIntegerSplit
import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger[] doBigIntegerSplit(BigInteger left, BigInteger right, int expectSliceNumber) {
if (expectSliceNumber < 1) {
throw new IllegalArgumentException(String.format(
"切分份数不能小于1. 此处:expectSliceNumber=[%s].", expectSliceNumber));
}
if (null == left || null == right) {
throw new IllegalArgumentException(String.format(
"对 BigInteger 进行切分时,其左右区间不能为 null. 此处:left=[%s],right=[%s].", left, right));
}
if (left.compareTo(right) == 0) {
return new BigInteger[]{left, right};
} else {
// 调整大小顺序,确保 left < right
if (left.compareTo(right) > 0) {
BigInteger temp = left;
left = right;
right = temp;
}
//left < right
BigInteger endAndStartGap = right.subtract(left);
BigInteger step = endAndStartGap.divide(BigInteger.valueOf(expectSliceNumber));
BigInteger remainder = endAndStartGap.remainder(BigInteger.valueOf(expectSliceNumber));
//remainder 不可能超过expectSliceNumber,所以不需要检查remainder的 Integer 的范围
// 这里不能 step.intValue()==0,因为可能溢出
if (step.compareTo(BigInteger.ZERO) == 0) {
expectSliceNumber = remainder.intValue();
}
BigInteger[] result = new BigInteger[expectSliceNumber + 1];
result[0] = left;
result[expectSliceNumber] = right;
BigInteger lowerBound;
BigInteger upperBound = left;
for (int i = 1; i < expectSliceNumber; i++) {
lowerBound = upperBound;
upperBound = lowerBound.add(step);
upperBound = upperBound.add((remainder.compareTo(BigInteger.valueOf(i)) >= 0)
? BigInteger.ONE : BigInteger.ZERO);
result[i] = upperBound;
}
return result;
}
}