Java BigInteger Power pow(BigInteger base, BigInteger exponent)

Here you can find the source of pow(BigInteger base, BigInteger exponent)

Description

pow

License

Open Source License

Declaration

public static BigInteger pow(BigInteger base, BigInteger exponent) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    public static BigInteger pow(BigInteger base, BigInteger exponent) {
        BigInteger result = BigInteger.ONE;
        while (exponent.signum() > 0) {
            if (exponent.testBit(0))
                result = result.multiply(base);
            base = base.multiply(base);/*from w w w.j av a  2  s. c  o  m*/
            exponent = exponent.shiftRight(1);
        }
        return result;
    }
}

Related

  1. Power(BigInteger base, int exp)
  2. powerToEnergy(BigInteger power, Integer ptuDuration)