public static String bcpowmod(Environment env, Memory _base, Memory _exp, Memory _modulus, int scale) {
        BigDecimal base = toBigDecimal(_base);
        BigDecimal exp = toBigDecimal(_exp);
        BigDecimal modulus = toBigDecimal(_modulus);

        if (base.scale() != 0) {
            BigInteger expI = exp.toBigInteger();
            BigDecimal pow = bcpowImpl(base, expI, scale);
            return pow.remainder(modulus, MathContext.UNLIMITED).toString();
        } else {
            BigInteger baseI = base.toBigInteger();
            BigInteger expI = exp.toBigInteger();
            BigInteger modulusI = modulus.toBigInteger();

            BigInteger result = baseI.modPow(expI, modulusI);
            return result.toString();
        }
    }
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