当前位置: 首页>>代码示例>>Java>>正文


Java BigInteger.remainder方法代码示例

本文整理汇总了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;
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:19,代码来源:CalCpowb.java

示例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;
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:17,代码来源:CalCln.java

示例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");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:KeyUtil.java

示例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));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:XMLGregorianCalendarImpl.java

示例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));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:XMLGregorianCalendarImpl.java

示例6: mod

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger mod(BigInteger arg0, BigInteger arg1) {
    return arg0.remainder(arg1);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:5,代码来源:BigIntAlgebra.java

示例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;
    }
}
 
开发者ID:yaogdu,项目名称:datax,代码行数:52,代码来源:RangeSplitUtil.java


注:本文中的java.math.BigInteger.remainder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。