* @param decimalPlaces
     * @return 
     */
    public static BigDecimal log(
            int base_int,
            BigDecimal x,
            int decimalPlaces,
            RoundingMode a_RoundingMode) {
        // Deal with special cases
        if (x.compareTo(BigDecimal.ZERO) != 1) {
            throw new IllegalArgumentException("x <= 0");
        }
        if (x.compareTo(BigDecimal.ONE) == 0) {
            return BigDecimal.ZERO;
        }
        if (new BigDecimal("" + base_int).compareTo(x) == 0) {
            return BigDecimal.ONE;
        }
        if (x.compareTo(BigDecimal.ONE) == -1) {
            BigDecimal oneOverX = Generic_BigDecimal.reciprocal(
                    x, 
                    decimalPlaces, 
                    a_RoundingMode);
            BigDecimal logOneOverX = Generic_BigDecimal.log(
                    base_int,
                    oneOverX,
                    decimalPlaces,
                    a_RoundingMode);
            return logOneOverX.negate();
        }
        BigDecimal result = BigDecimal.ZERO;
        BigDecimal input = new BigDecimal(x.toString());
        int scale = input.precision() + decimalPlaces;
        int maxite = Math.max(base_int, 10000);
        int ite = 0;
        BigDecimal maxError_BigDecimal = new BigDecimal(
                BigInteger.ONE, decimalPlaces + 1);
        //System.out.println("epsilon_BigDecimal " + epsilon_BigDecimal);
        //System.out.println("scale " + scale);
        BigDecimal base_BigDecimal = new BigDecimal(base_int);
        while (input.compareTo(base_BigDecimal) == 1) {
            result = result.add(BigDecimal.ONE);
            input = input.divide(base_BigDecimal, scale, a_RoundingMode);
        }
        BigDecimal fraction = new BigDecimal("0.5");
        input = input.multiply(input);
        BigDecimal resultplusfraction = result.add(fraction);
        int decimalPlacesSafer = Math.max(decimalPlaces * 2, decimalPlaces + 10); // Not sure this is safe enough, maybe log(base_int,maxite,0) would be?

        boolean condition = true;
        do {
//        while (((resultplusfraction).compareTo(result) == 1)
//                && (input.compareTo(BigDecimal.ONE) == 1)) {
            if (input.compareTo(base_BigDecimal) == 1) {
                input = input.divide(base_BigDecimal, scale, a_RoundingMode);
                result = result.add(fraction);
            }
            input = multiplyRoundIfNecessary(
                    input,
                    input,
                    decimalPlacesSafer,
                    a_RoundingMode);
            fraction = fraction.divide(TWO, scale, a_RoundingMode);
            resultplusfraction = result.add(fraction);
            if (fraction.abs().compareTo(maxError_BigDecimal) == -1) {
                break;
            }
            if (maxite == ite) {
                System.out.println(
                        "Warning: maxite reached in "
                        + Generic_BigDecimal.class.getName()
                        + ".log(int,BigDecimal,int,RoundingMode) "
                        + " log("
                        + base_int + ", "
                        + x + ", "
                        + decimalPlaces + ", "
                        + a_RoundingMode.toString() + ") "
                        + result.toString());
                break;
            }
            ite++;

            condition =
                    ((resultplusfraction).compareTo(result) == 1)
                    && (input.compareTo(BigDecimal.ONE) == 1);

        }