private static BigDecimal bcpowImpl(BigDecimal base, BigInteger exp, int scale) {
        if (exp.compareTo(BigInteger.ZERO) == 0)
            return BigDecimal.ONE;

        boolean isNeg;
        if (exp.compareTo(BigInteger.ZERO) < 0) {
            isNeg = true;
            exp = exp.negate();
        }
        else
            isNeg = false;

        BigDecimal result = BigDecimal.ZERO;

        while (exp.compareTo(BigInteger.ZERO) > 0) {
            BigInteger expSub = exp.min(INTEGER_MAX);
            exp = exp.subtract(expSub);

            result = result.add(base.pow(expSub.intValue()));
        }

        if (isNeg)
            result = BigDecimal.ONE.divide(result, scale + 2, RoundingMode.DOWN);

        result = result.setScale(scale, RoundingMode.DOWN);

        if (result.compareTo(BigDecimal.ZERO) == 0)
            return BigDecimal.ZERO;

        result = result.stripTrailingZeros();
        return result;
    }
bcmath extension
http://www.php.net/manual/ru/book.bc.php
exts/jphp-zend-ext/src/main/java/org/develnext/jphp/zend/ext/standard/BCMathFunctions.java