public static Memory bcsqrt(Environment env, Memory operand, int scale) {
        BigDecimal value = toBigDecimal(operand);

        int compareToZero = value.compareTo(BigDecimal.ZERO);

        if (compareToZero < 0) {
            return Memory.NULL;
        } else if (compareToZero == 0) {
            return new StringMemory("0");
        }

        int compareToOne = value.compareTo(BigDecimal.ONE);

        if (compareToOne == 0)
            return new StringMemory("1");

        int cscale;

        BigDecimal initialGuess;
        if (compareToOne < 1) {
            initialGuess = BigDecimal.ONE;
            cscale = value.scale();
        } else {
            BigInteger integerPart = value.toBigInteger();

            int length = integerPart.toString().length();

            if ((length % 2) == 0)
                length--;

            length /= 2;
            initialGuess = BigDecimal.ONE.movePointRight(length);
            cscale = Math.max(scale, value.scale()) + 2;
        }

        BigDecimal guess = initialGuess;
        BigDecimal lastGuess;

        for (int iteration = 0; iteration < 50; iteration++) {
            lastGuess = guess;
            guess = value.divide(guess, cscale, RoundingMode.DOWN);
            guess = guess.add(lastGuess);
            guess = guess.divide(DECIMAL_TWO, cscale, RoundingMode.DOWN);

            if (lastGuess.equals(guess)) {
                break;
            }
        }

        value = guess;
        value = value.setScale(scale, RoundingMode.DOWN);
        return new StringMemory(value.toPlainString());
    }
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