'Returns the natural (base e) logarithm of self.'

def ln(self, context=None):

    if (context is None):
        context = getcontext()
    ans = self._check_nans(context=context)
    if ans:
        return ans
    else:
        if (not self):
            return _NegativeInfinity
        if (self._isinfinity() == 1):
            return _Infinity
        if (self == _One):
            return _Zero
        if (self._sign == 1):
            return context._raise_error(InvalidOperation, 'ln    of    a    negative    value')
        op = _WorkRep(self)
        (c, e) = (op.int, op.exp)
        p = context.prec
        places = ((p - self._ln_exp_bound()) + 2)
        while True:
            coeff = _dlog(c, e, places)
            if (coeff % (5 * (10 ** ((len(str(abs(coeff))) - p) - 1)))):
                break
            places += 3
        ans = _dec_from_triple(int((coeff < 0)), str(abs(coeff)), (- places))
        context = context._shallow_copy()
        rounding = context._set_rounding(ROUND_HALF_EVEN)
        ans = ans._fix(context)
        context.rounding = rounding
        return ans
