Repository: sympy/sympy
File: sympy/core/evalf.py (Python)

Code before:
    if xre is xim is None:
        # Dear reviewer, I do not know what -inf is;
        # it looks to be (1, 0, -789, -3)
        # but I'm not sure in general,
        # so we just let mpmath figure
        # it out by taking log of 0 directly.
        # It would be better to return -inf instead.
        xre = fzero

    if xim:
        from sympy.functions.elementary.complexes import Abs
        from sympy.functions.elementary.exponential import log

        # XXX: use get_abs etc instead
        re = evalf_log(
            log(Abs(arg, evaluate=False), evaluate=False), prec, options)
        im = mpf_atan2(xim, xre or fzero, prec)
        return re[0], im, re[2], prec

    imaginary_term = (mpf_cmp(xre, fzero) < 0)

    re = mpf_log(mpf_abs(xre), prec, rnd)
    size = fastlog(re)
    if prec - size > workprec:
        from .add import Add
        # We actually need to compute 1+x accurately, not x
        add = Add(S.NegativeOne, arg, evaluate=False)
        xre, xim, xre_acc, _ = evalf_add(add, prec, options)
        if xre != fzero and (xre_acc is None or xre_acc > 1):
            prec2 = workprec - fastlog(xre)
            # xre is now x - 1 so we add 1 back here to calculate x
            re = mpf_log(mpf_abs(mpf_add(xre, fone, prec2)), prec, rnd)

    re_acc = prec

    if imaginary_term:
        return re, mpf_pi(prec), re_acc, prec
    else:
        return re, None, re_acc, None


def evalf_atan(v: 'atan', prec: int, options: OPT_DICT) -> TMP_RES:
    arg = v.args[0]
    result = evalf(arg, prec + 5, options)
    if result is S.ComplexInfinity:
        return result
    xre, xim, reacc, imacc = result
    if xre is xim is None:
        return (None,)*4
    if xim:
        raise NotImplementedError

Review comment (suggestion):
The comment says "We actually need to compute 1+x accurately, not x" but the code computes Add(S.NegativeOne, arg), which calculates arg - 1, not 1 + x. The comment should be updated to say "We actually need to compute x-1 accurately" or "We compute (arg - 1) to maintain precision" to match what the code actually does.
```suggestion
        # We actually need to compute x-1 accurately, not x
```

Code after:
    if xre is xim is None:
        # Dear reviewer, I do not know what -inf is;
        # it looks to be (1, 0, -789, -3)
        # but I'm not sure in general,
        # so we just let mpmath figure
        # it out by taking log of 0 directly.
        # It would be better to return -inf instead.
        xre = fzero

    if xim:
        from sympy.functions.elementary.complexes import Abs
        from sympy.functions.elementary.exponential import log

        # XXX: use get_abs etc instead
        re = evalf_log(
            log(Abs(arg, evaluate=False), evaluate=False), prec, options)
        im = mpf_atan2(xim, xre or fzero, prec)
        return re[0], im, re[2], prec

    imaginary_term = (mpf_cmp(xre, fzero) < 0)

    re = mpf_log(mpf_abs(xre), prec, rnd)
    size = fastlog(re)
    if prec - size > workprec:
        from .add import Add
        # We actually need to compute x-1 accurately, not x
        add = Add(S.NegativeOne, arg, evaluate=False)
        xre, xim, xre_acc, _ = evalf_add(add, prec, options)
        if xre != fzero and (xre_acc is None or xre_acc > 1):
            prec2 = workprec - fastlog(xre)
            # xre is now x - 1 so we add 1 back here to calculate x
            re = mpf_log(mpf_abs(mpf_add(xre, fone, prec2)), prec, rnd)

    re_acc = prec

    if imaginary_term:
        return re, mpf_pi(prec), re_acc, prec
    else:
        return re, None, re_acc, None


def evalf_atan(v: 'atan', prec: int, options: OPT_DICT) -> TMP_RES:
    arg = v.args[0]
    result = evalf(arg, prec + 5, options)
    if result is S.ComplexInfinity:
        return result
    xre, xim, reacc, imacc = result
    if xre is xim is None:
        return (None,)*4
    if xim:
        raise NotImplementedError