nd4j-common/src/main/java/org/nd4j/linalg/util/BigDecimalMath.java
static public BigDecimal log(final Rational r, final MathContext mc) {
        /* the value is undefined if x is negative.
         */
        if (r.compareTo(Rational.ZERO) <= 0) {
            throw new ArithmeticException("Cannot take log of negative " + r.toString());
        } else if (r.compareTo(Rational.ONE) == 0) {
            return BigDecimal.ZERO;
        } else {
            /* log(r+epsr) = log(r)+epsr/r. Convert the precision to an absolute error in the result.
             * eps contains the required absolute error of the result, epsr/r.
             */
            double eps = prec2err(Math.log(r.doubleValue()), mc.getPrecision());
            /* Convert this further into a requirement of the relative precision in r, given that
             * epsr/r is also the relative precision of r. Add one safety digit.
             */
            MathContext mcloc = new MathContext(1 + err2prec(eps));
            final BigDecimal resul = log(r.BigDecimalValue(mcloc));
            return resul.round(mc);
        }
    }
static public BigDecimal log(final Rational r, final MathContext mc) {
        /* the value is undefined if x is negative.
         */
        if (r.compareTo(Rational.ZERO) <= 0) {
            throw new ArithmeticException("Cannot take log of negative " + r.toString());
        } else if (r.compareTo(Rational.ONE) == 0) {
            return BigDecimal.ZERO;
        } else {
            /* log(r+epsr) = log(r)+epsr/r. Convert the precision to an absolute error in the result.
             * eps contains the required absolute error of the result, epsr/r.
             */
            double eps = prec2err(Math.log(r.doubleValue()), mc.getPrecision());
            /* Convert this further into a requirement of the relative precision in r, given that
             * epsr/r is also the relative precision of r. Add one safety digit.
             */
            MathContext mcloc = new MathContext(1 + err2prec(eps));
            final BigDecimal resul = log(r.BigDecimalValue(mcloc));
            return resul.round(mc);
        }
    }
The natural logarithm.

@param r  The main argument, a strictly positive value.
@param mc The requirements on the precision.
@return ln(r).