Examples of pow()


Examples of java.math.BigInteger.pow()

  private BigInteger num;

  @Override
  public void init(Object... inits) {
    BigInteger i = new BigInteger("2");
    num = i.pow(1000);
  }

  @Override
  public void solve() {
    String s = num.toString();
View Full Code Here

Examples of java.math.BigInteger.pow()

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

Examples of java.math.BigInteger.pow()

        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

Examples of java.math.BigInteger.pow()

  public void testSqrtFloor() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
      for (RoundingMode mode : asList(FLOOR, DOWN)) {
        BigInteger result = BigIntegerMath.sqrt(x, mode);
        assertTrue(result.compareTo(ZERO) > 0);
        assertTrue(result.pow(2).compareTo(x) <= 0);
        assertTrue(result.add(ONE).pow(2).compareTo(x) > 0);
      }
    }
  }
View Full Code Here

Examples of java.math.BigInteger.pow()

  public void testSqrtCeiling() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
      for (RoundingMode mode : asList(CEILING, UP)) {
        BigInteger result = BigIntegerMath.sqrt(x, mode);
        assertTrue(result.compareTo(ZERO) > 0);
        assertTrue(result.pow(2).compareTo(x) >= 0);
        assertTrue(result.signum() == 0 || result.subtract(ONE).pow(2).compareTo(x) < 0);
      }
    }
  }
View Full Code Here

Examples of java.math.BigInteger.pow()

  // Relies on the correctness of sqrt(BigInteger, FLOOR).
  public void testSqrtExact() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
      BigInteger floor = BigIntegerMath.sqrt(x, FLOOR);
      // We only expect an exception if x was not a perfect square.
      boolean isPerfectSquare = floor.pow(2).equals(x);
      try {
        assertEquals(floor, BigIntegerMath.sqrt(x, UNNECESSARY));
        assertTrue(isPerfectSquare);
      } catch (ArithmeticException e) {
        assertFalse(isPerfectSquare);
View Full Code Here

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

Examples of javax.measure.unit.Unit.pow()

        if (javax.measure.unit.ProductUnit.class.isInstance(u)){
            ProductUnit pu=(ProductUnit)u;
            for (int i=0;i<pu.getUnitCount();++i){
                /* First check to see if this unit needs split */
                Unit ux =splitUnits(pu.getUnit(i));
                retval=retval.times(ux.pow(pu.getUnitPow(i)));
            }
            /* Now split again */
            Logger.getLogger("com.CompPad").log(Level.FINE,"ProductUnit "
                    + pu.getUnitCount());
        }
View Full Code Here

Examples of javax.measure.unit.Unit.pow()

        if (javax.measure.unit.ProductUnit.class.isInstance(u)){
            ProductUnit pu=(ProductUnit)u;
            for (int i=0;i<pu.getUnitCount();++i){
                /* First check to see if this unit needs split */
                Unit ux =splitUnits(pu.getUnit(i));
                retval=retval.times(ux.pow(pu.getUnitPow(i)));
            }
            /* Now split again */
            Logger.getLogger("com.CompPad").log(Level.FINE,"ProductUnit "
                    + pu.getUnitCount());
        }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec.pow()

          power = (ConsCell) power.getCar();
        current.getNextConsCell().remove();
        power = parser.run(parser.preProcess(power));
        if (power.getCarType() != ConsType.NUMBER || power.length() != 1)
          throw new InvalidUnitException(current.getCar() + " is raised to an invalid power.", nl);
        partial = partial.pow((BigDec) power.getCar());
      }
      factor = divide ? factor.divide(partial) : factor.multiply(partial);
    } while (!(current = current.getNextConsCell()).isNull());
    return factor;
  }
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.