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


Java BigInteger.subtract方法代码示例

本文整理汇总了Java中java.math.BigInteger.subtract方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.subtract方法的具体用法?Java BigInteger.subtract怎么用?Java BigInteger.subtract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


在下文中一共展示了BigInteger.subtract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toSignedTarget

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Coerces an integral value (BigInteger) to its corresponding signed
 * representation, if the target type of this expression is signed.
 * @param  b  The BigInteger to be coerced.
 * @return  the value of an integral type coerced to its corresponding
 *  signed integral type, if the target type of this expression is
 *  signed.
 **/
protected BigInteger toSignedTarget (BigInteger b)
{
  if (type ().equals ("short"))
  {
    if (b != null && b.compareTo (sMax) > 0)
      return b.subtract (twoPow16);
  }
  else if (type ().equals ("long"))
  {
    if (b != null && b.compareTo (lMax) > 0)
      return b.subtract (twoPow32);
  }
  else if (type ().equals ("long long"))
  {
    if (b != null && b.compareTo (llMax) > 0)
      return b.subtract (twoPow64);
  }
  return b;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:Expression.java

示例2: execute

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public void execute(EVMState state, Opcode opcode) throws EVMException {
    EVMStack stack = state.getStack();
    TraceableWord traceableWord0 = stack.pop();
    TraceableWord traceableWord1 = stack.pop();

    TraceTree trace1 = traceableWord0.getTrace();
    TraceTree trace2 = traceableWord1.getTrace();

    BigInteger element0 = new BigInteger(traceableWord0.getBytes());
    BigInteger element1 = new BigInteger(traceableWord1.getBytes());

    BigInteger result = element0.subtract(element1);

    TraceableWord resultTraceableWord = new TraceableWord(result.toByteArray());
    TraceTree traceTree = buildTraceTree(opcode, resultTraceableWord, Lists.of(traceableWord0, traceableWord1));
    traceTree.addChild(trace1);
    traceTree.addChild(trace2);
    resultTraceableWord.setTrace(traceTree);
    stack.push(resultTraceableWord);
}
 
开发者ID:fergarrui,项目名称:ethereum-bytecode-analyzer,代码行数:22,代码来源:Sub.java

示例3: getBalance

import java.math.BigInteger; //导入方法依赖的package包/类
public BigInteger getBalance() {

        BigInteger balance =
                repository.getBalance(this.getAddress());

        synchronized (getPendingTransactions()) {
            if (!getPendingTransactions().isEmpty()) {

                for (Transaction tx : getPendingTransactions()) {
                    if (Arrays.equals(getAddress(), tx.getSender())) {
                        balance = balance.subtract(new BigInteger(1, tx.getValue()));
                    }

                    if (Arrays.equals(getAddress(), tx.getReceiveAddress())) {
                        balance = balance.add(new BigInteger(1, tx.getValue()));
                    }
                }
                // todo: calculate the fee for pending
            }
        }


        return balance;
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:25,代码来源:Account.java

示例4: visitArithmeticBinary

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger visitArithmeticBinary(ArithmeticBinaryContext ctx)
{
    BigInteger left = visit(ctx.left);
    BigInteger right = visit(ctx.right);
    switch (ctx.operator.getType()) {
        case PLUS:
            return left.add(right);
        case MINUS:
            return left.subtract(right);
        case ASTERISK:
            return left.multiply(right);
        case SLASH:
            return left.divide(right);
        default:
            throw new IllegalStateException("Unsupported binary operator " + ctx.operator.getText());
    }
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:19,代码来源:TypeCalculation.java

示例5: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String[] args) {
    String k;
    int i, n;
    BigInteger[] a = new BigInteger[1801];
    Scanner in = new Scanner(System.in);
    n = in.nextInt();
    k = in.next();
    BigInteger e = new BigInteger(k);
    BigInteger f1 = new BigInteger(String.valueOf(1));
    a[0] = e.subtract(f1);
    a[1] = e.multiply(a[0]);
    for (i = 2; i < n; i++) {
        a[i] = (a[i - 1].add(a[i - 2])).multiply(e.subtract(f1));
    }
    System.out.print(a[((n - 1))]);
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:17,代码来源:KbasedNum2_1012.java

示例6: testIsLongTooLessValue

import java.math.BigInteger; //导入方法依赖的package包/类
@Test
public void testIsLongTooLessValue() throws Exception {
    ParameterDefinition paramDef = initLongParamDef();
    VOParameterDefinition voParamDef = ParameterDefinitionAssembler
            .toVOParameterDefinition(paramDef, facade);
    VOParameter param = new VOParameter(voParamDef);
    BigInteger bigInt = BigInteger.valueOf(Long.MIN_VALUE);
    BigInteger subtract = BigInteger.valueOf(1);
    bigInt = bigInt.subtract(subtract);
    param.setValue(String.valueOf(bigInt));
    try {
        ParameterAssembler.validateParameter(param, paramDef);
        Assert.fail("Operation must fail, as the passed value is not a valid integer");
    } catch (ValidationException e) {
        Assert.assertEquals("Wrong message key",
                "ex.ValidationException.LONG", e.getMessageKey());
        Assert.assertEquals("Wrong param number", 1,
                e.getMessageParams().length);
        Assert.assertEquals("Wrong params", "-9223372036854775809",
                e.getMessageParams()[0]);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:ParameterAssemblerTest.java

示例7: montgomeryMultiply

import java.math.BigInteger; //导入方法依赖的package包/类
BigInteger montgomeryMultiply(BigInteger a, BigInteger b, BigInteger N,
        int len, BigInteger n_prime)
        throws Throwable {
    BigInteger T = a.multiply(b);
    BigInteger R = BigInteger.ONE.shiftLeft(len*32);
    BigInteger mask = R.subtract(BigInteger.ONE);
    BigInteger m = (T.and(mask)).multiply(n_prime);
    m = m.and(mask); // i.e. m.mod(R)
    T = T.add(m.multiply(N));
    T = T.shiftRight(len*32); // i.e. T.divide(R)
    if (T.compareTo(N) > 0) {
        T = T.subtract(N);
    }
    return T;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:MontgomeryMultiplyTest.java

示例8: bruteForce

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * BruteForce cracking algorithm
 * @param pbKey Public key to crack
 * @param pbExp Public exponent of the key to crack
 */
public static void bruteForce(BigInteger pbKey, BigInteger pbExp) {

	BigInteger p = bigIntSqRootFloor((BigInteger)pbKey);
	while (pbKey.mod(p).compareTo(BigInteger.ZERO) != 0) {
		p = p.subtract(BigInteger.ONE);
	}
	BigInteger q = pbKey.divide(p);
	calcPrivateExp(p, q, pbExp);

}
 
开发者ID:cybernova,项目名称:RSAbreaker,代码行数:16,代码来源:RSAbreaker.java

示例9: binomial

import java.math.BigInteger; //导入方法依赖的package包/类
/** Evaluate binomial(n,k).
* @param n The upper index 
* @param k The lower index
* @return The binomial coefficient
* @since 2008-10-15
* @author Richard J. Mathar
*/
static public BigInteger binomial(final BigInteger n, final BigInteger k)
{
        /* binomial(n,0) =1 
        */
        if ( k.compareTo(BigInteger.ZERO) == 0 ) 
                return(BigInteger.ONE) ;

        BigInteger bin = n;

        /* the following version first calculates n(n-1)(n-2)..(n-k+1)
        * in the first loop, and divides this product through k(k-1)(k-2)....2
        * in the second loop. This is rather slow and replaced by a faster version
        * below
        * BigInteger n2 = bin ;
        * BigInteger i= k.subtract(BigInteger.ONE) ;
        * for( ; i.compareTo(BigInteger.ONE) >= 0 ; i = i.subtract(BigInteger.ONE) )
        *       bin = bin.multiply(n2.subtract(i)) ;
        * i= BigInteger.valueOf(k) ;
        * for( ; i.compareTo(BigInteger.ONE) == 1 ; i = i.subtract(BigInteger.ONE) )
        *       bin = bin.divide(i) ;
        */

        /* calculate n then n(n-1)/2 then n(n-1)(n-2)(2*3) etc up to n(n-1)..(n-k+1)/(2*3*..k)
        * This is roughly the best way to keep the individual intermediate products small
        * and in the integer domain. First replace C(n,k) by C(n,n-k) if n-k<k.
        */
        BigInteger truek = k ;
        if ( n.subtract(k).compareTo(k) < 0 )
                truek = n.subtract(k) ;

        /* Calculate C(num,truek) where num=n and truek is the smaller of n-k and k.
        * Have already initialized bin=n=C(n,1) above. Start definining the factorial
        * in the denominator, named fden
        */
        BigInteger i = BigInteger.valueOf(2L) ;
        BigInteger num = n ;
        /* a for-loop   (i=2;i<= truek;i++)
        */
        for( ; i.compareTo(truek) <= 0 ; i = i.add(BigInteger.ONE) )
        {
                /* num = n-i+1 after this operation
                */
                num = num.subtract(BigInteger.ONE) ;
                /* multiply by (n-i+1)/i
                */
                bin = (bin.multiply(num)).divide(i) ;
        }
        return ( bin) ;
}
 
开发者ID:Baizey,项目名称:Helpers,代码行数:57,代码来源:BigIntegerMath.java

示例10: transform

import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
  double floatValue;
  if (value.getType().toLowerCase().equals("s")
      || value.getType().toLowerCase().equals("string")) {
    return result;
  }

  if (value.getLSB() != null) {
    BigInteger val = parse(value, result);

    if (!value.mask().equals(BigInteger.ZERO)) {
      val = val.and(value.mask());
    }

    if (!value.shift().equals(0)) {
      val = val.shiftRight(value.shift());
    }

    if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
      BigInteger complement =
          new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
      val = val.subtract(complement);
    }

    if (!objectCache.getTransformData()) {
      int intValue = val.intValue();
      return String.valueOf(intValue);
    }

    floatValue = val.doubleValue();
  } else {
    floatValue = Float.parseFloat(result);
  }

  if (!value.base().equals(0)) {
    floatValue = Math.pow(value.base(), floatValue);
  }

  floatValue = floatValue * value.scale();
  floatValue = floatValue + value.offset();

  if (value.getType().toLowerCase().equals("f")
      || value.getType().toLowerCase().equals("float")) {
    return String.valueOf(floatValue);
  }

  return String.valueOf(Math.round(floatValue));
}
 
开发者ID:mgjeong,项目名称:device-opcua-java,代码行数:49,代码来源:ObjectTransform.java

示例11: det

import java.math.BigInteger; //导入方法依赖的package包/类
/** Determinant of an integer square matrix.
* @param A The square matrix.
*  If column and row dimensions are unequal, an ArithmeticException is thrown.
* @return The determinant.
* @since 2010-08-27
* @author Richard J. Mathar
*/
static public BigInteger det(final BigInteger[][] A) throws ArithmeticException
{
        BigInteger d = BigInteger.ZERO ;
        /* row size */
        final int rL = A.length ;
        if ( rL == 0 )
                throw new ArithmeticException("zero row count in matrix") ;
        /* column size */
        final int cL = A[0].length ;
        if ( cL != rL )
                throw new ArithmeticException("Non-square matrix dim "+rL + " by " + cL) ;

        /* Compute the low-order cases directly.
        */
        if ( rL == 1 )
                return A[0][0] ;

        else if ( rL == 2)
        {
                d = A[0][0].multiply(A[1][1]) ;
                return d.subtract( A[0][1].multiply(A[1][0])) ;
        }
        else
        {
                /* Work arbitrarily along the first column of the matrix */
                for (int r = 0  ; r < rL  ; r++)
                {
                        /* Do not consider minors that do no contribute anyway
                        */
                        if ( A[r][0].compareTo(BigInteger.ZERO) != 0 )
                        {
                                final BigInteger M[][] = minor(A,r,0) ;
                                final BigInteger m = A[r][0].multiply( det(M)) ;
                                /* recursive call */
                                if ( r % 2 == 0)
                                        d = d.add(m) ;
                                else
                                        d = d.subtract(m) ;
                        }
                }
        }
        return d;
}
 
开发者ID:Baizey,项目名称:Helpers,代码行数:51,代码来源:BigIntegerMath.java

示例12: generateKeyPair

import java.math.BigInteger; //导入方法依赖的package包/类
public KeyPair generateKeyPair() {
    // accommodate odd key sizes in case anybody wants to use them
    int lp = (keySize + 1) >> 1;
    int lq = keySize - lp;
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    BigInteger e = publicExponent;
    while (true) {
        // generate two random primes of size lp/lq
        BigInteger p = BigInteger.probablePrime(lp, random);
        BigInteger q, n;
        do {
            q = BigInteger.probablePrime(lq, random);
            // convention is for p > q
            if (p.compareTo(q) < 0) {
                BigInteger tmp = p;
                p = q;
                q = tmp;
            }
            // modulus n = p * q
            n = p.multiply(q);
            // even with correctly sized p and q, there is a chance that
            // n will be one bit short. re-generate the smaller prime if so
        } while (n.bitLength() < keySize);

        // phi = (p - 1) * (q - 1) must be relative prime to e
        // otherwise RSA just won't work ;-)
        BigInteger p1 = p.subtract(BigInteger.ONE);
        BigInteger q1 = q.subtract(BigInteger.ONE);
        BigInteger phi = p1.multiply(q1);
        // generate new p and q until they work. typically
        // the first try will succeed when using F4
        if (e.gcd(phi).equals(BigInteger.ONE) == false) {
            continue;
        }

        // private exponent d is the inverse of e mod phi
        BigInteger d = e.modInverse(phi);

        // 1st prime exponent pe = d mod (p - 1)
        BigInteger pe = d.mod(p1);
        // 2nd prime exponent qe = d mod (q - 1)
        BigInteger qe = d.mod(q1);

        // crt coefficient coeff is the inverse of q mod p
        BigInteger coeff = q.modInverse(p);

        try {
            PublicKey publicKey = new RSAPublicKeyImpl(n, e);
            PrivateKey privateKey =
                    new RSAPrivateCrtKeyImpl(n, e, d, p, q, pe, qe, coeff);
            return new KeyPair(publicKey, privateKey);
        } catch (InvalidKeyException exc) {
            // invalid key exception only thrown for keys < 512 bit,
            // will not happen here
            throw new RuntimeException(exc);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:RSAKeyPairGenerator.java

示例13: previous

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger previous(BigInteger value) {
  return value.subtract(BigInteger.ONE);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:5,代码来源:DiscreteDomain.java

示例14: getKeysInRange

import java.math.BigInteger; //导入方法依赖的package包/类
public static List<byte[]> getKeysInRange(byte[] start, byte[] stop, int numOfKeys) {
  byte[] aPadded;
  byte[] bPadded;
  Set<byte[]> result = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
  if (start.length < stop.length) {
    aPadded = Bytes.padTail(start, stop.length - start.length);
    bPadded = stop;
  } else if (stop.length < start.length) {
    aPadded = start;
    bPadded = Bytes.padTail(stop, start.length - stop.length);
  } else {
    aPadded = start;
    bPadded = stop;
  }
  if (Bytes.compareTo(aPadded, bPadded) >= 0) {
    throw new IllegalArgumentException("b <= a");
  }
  if (numOfKeys <= 0) {
    throw new IllegalArgumentException("numOfKeys cannot be <= 0");
  }

  byte[] prependHeader = {1, 0};
  final BigInteger startBI = new BigInteger(Bytes.add(prependHeader, aPadded));
  final BigInteger stopBI = new BigInteger(Bytes.add(prependHeader, bPadded));

  BigInteger diffBI = stopBI.subtract(startBI);
  long difference = diffBI.longValue();
  if (diffBI.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) > 0) {
    difference = Long.MAX_VALUE;
  }
  byte[] padded = null;
  for (int i = 0; i < numOfKeys; i++) {
    do {
      BigInteger keyBI = startBI.add(BigInteger.valueOf(nextLong(0, difference)));
      padded = keyBI.toByteArray();
      if (padded[1] == 0) {
        padded = Bytes.tail(padded, padded.length - 2);
      } else {
        padded = Bytes.tail(padded, padded.length - 1);
      }
    } while (!result.add(padded));
  }
  return new ArrayList<byte[]>(result);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:45,代码来源:KeyUtils.java

示例15: subtract

import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger subtract( BigInteger a, BigInteger b ) {
   return a.subtract( b );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:4,代码来源:Math.java


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