Package java.math

Examples of java.math.BigInteger.pow()


        // Test some known Mersenne primes (2^n)-1
        // The array holds the exponents, not the numbers being tested
        for (int i=0; i<NUM_MERSENNES_TO_TEST; i++) {
            p1 = new BigInteger("2");
            p1 = p1.pow(mersenne_powers[i]);
            p1 = p1.subtract(BigInteger.ONE);
            if (!p1.isProbablePrime(100)) {
                System.err.println("Mersenne prime "+i+ " failed.");
                failCount++;
            }
View Full Code Here


        BigInteger number = BigInteger.ZERO;
        for (int i = 0; i < binaryNumber.length(); i++) {
            if (binaryNumber.charAt(i) == '1') {
                BigInteger powerOfTwo = BigInteger.valueOf(2);
                int exp = binaryNumber.length() - i - 1;
                powerOfTwo = powerOfTwo.pow(exp);
                number = number.add(powerOfTwo);
            }
        }
        return number.toString();
    }
View Full Code Here

        BigInteger  result = BigInteger.ZERO;
        BigInteger  base = BigInteger.valueOf(alphabets.length());
        int         digits = str.length();
        for (int i = 0; i < digits; i++) {
            int digit = alphabets.indexOf(str.charAt(digits - i - 1));
            result = result.add(BigInteger.valueOf(digit).multiply(base.pow(i)));
        }
        return result;
    }

    public static String encode58(BigInteger number) {
View Full Code Here

        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
        int aSign = 1;
        int exp = -5;
        BigInteger aNumber = new BigInteger(aSign, aBytes);
        try {
            aNumber.pow(exp);
            fail("ArithmeticException has not been caught");
        } catch (ArithmeticException e) {
            assertEquals("Improper exception message", "Negative exponent", e.getMessage());
        }
    }
View Full Code Here

    // capacity of 10 suffices for all x <= 10^(2^10).
    List<BigInteger> powersOf10 = new ArrayList<BigInteger>(10);
    BigInteger powerOf10 = BigInteger.TEN;
    while (x.compareTo(powerOf10) >= 0) {
      powersOf10.add(powerOf10);
      powerOf10 = powerOf10.pow(2);
    }
    BigInteger floorPow = BigInteger.ONE;
    int floorLog = 0;
    for (int i = powersOf10.size() - 1; i >= 0; i--) {
      BigInteger powOf10 = powersOf10.get(i);
View Full Code Here

      return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
    }
    BigInteger sqrtFloor = sqrtFloor(x);
    switch (mode) {
      case UNNECESSARY:
        checkRoundingUnnecessary(sqrtFloor.pow(2).equals(x)); // fall through
      case FLOOR:
      case DOWN:
        return sqrtFloor;
      case CEILING:
      case UP:
View Full Code Here

      case FLOOR:
      case DOWN:
        return sqrtFloor;
      case CEILING:
      case UP:
        return sqrtFloor.pow(2).equals(x) ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
      case HALF_DOWN:
      case HALF_UP:
      case HALF_EVEN:
        BigInteger halfSquare = sqrtFloor.pow(2).add(sqrtFloor);
        /*
 
View Full Code Here

        BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
        return new TypedValue(leftBigDecimal.pow(rightNumber.intValue()));
      }
      else if (leftNumber instanceof BigInteger) {
        BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class);
        return new TypedValue(leftBigInteger.pow(rightNumber.intValue()));
      }
      else if (leftNumber instanceof Double || rightNumber instanceof Double) {
        return new TypedValue(Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue()));
      }
      else if (leftNumber instanceof Float || rightNumber instanceof Float) {
View Full Code Here

        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
        int aSign = 1;
        int exp = -5;
        BigInteger aNumber = new BigInteger(aSign, aBytes);
        try {
            aNumber.pow(exp);
            fail("ArithmeticException has not been caught");
        } catch (ArithmeticException e) {
            assertEquals("Improper exception message", "Negative exponent", e.getMessage());
        }
    }
View Full Code Here

            // Size of the file pointer.
            final long size = filePointer.size();           

            BigInteger bigSize = BigInteger.valueOf(size);
            sumOfSquares = sumOfSquares.add(bigSize.pow(2));
            sum = sum.add(bigSize);
            numberOfShards++;

            if(numberOfShards % 1000 == 0) {
                GenomeLoc boundingRegion = getBoundingRegion(filePointer,genomeLocParser);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.