Repository: sympy/sympy
File: sympy/core/tests/test_evalf.py (Python)

Code before:
    # a complex number with `0.e-20` for imaginary part, even though `a5`
    # is a real number.
    zeta = Symbol('zeta')
    a5 = AlgebraicNumber(CRootOf(cyclotomic_poly(5), -1), [-1, -1, 0, 0], alias=zeta)
    z = a5.evalf()
    assert isinstance(z, Float)
    assert not hasattr(z, '_mpc_')
    assert hasattr(z, '_mpf_')


def test_issue_20733():
    expr = 1/((x - 9)*(x - 8)*(x - 7)*(x - 4)**2*(x - 3)**3*(x - 2))
    assert str(expr.evalf(1, subs={x:1})) == '-4.e-5'
    assert str(expr.evalf(2, subs={x:1})) == '-4.1e-5'
    assert str(expr.evalf(11, subs={x:1})) == '-4.1335978836e-5'
    assert str(expr.evalf(20, subs={x:1})) == '-0.000041335978835978835979'

    expr = Mul(*((x - i) for i in range(2, 1000)))
    assert srepr(expr.evalf(2, subs={x: 1})) == "Float('4.0271e+2561', precision=10)"
    assert srepr(expr.evalf(10, subs={x: 1})) == "Float('4.02790050126e+2561', precision=37)"
    assert srepr(expr.evalf(53, subs={x: 1})) == "Float('4.0279005012722099453824067459760158730668154575647110393e+2561', precision=179)"


def test_issue_28280():
    # This test demonstrates why `evalf_log` needs to specially handle
    # arguments close to 1.If the argument is evaluated directly
    # as `1 + 10**-10` at default precision,it loses the small
    # term and becomes exactly 1. This results in `log(1) -> 0`
    # causing `x > 20` to incorrectly evaluate to False.
    x = 20 + log(1 + S(10)**-10)
    assert x > 20
    y = 20 + log(1 + S(10)**-9)
    assert y > 20

Review comment (suggestion):
Missing space after period. Should be "arguments close to 1. If" instead of "arguments close to 1.If".
```suggestion
    # arguments close to 1. If the argument is evaluated directly
```

Code after:
    # a complex number with `0.e-20` for imaginary part, even though `a5`
    # is a real number.
    zeta = Symbol('zeta')
    a5 = AlgebraicNumber(CRootOf(cyclotomic_poly(5), -1), [-1, -1, 0, 0], alias=zeta)
    z = a5.evalf()
    assert isinstance(z, Float)
    assert not hasattr(z, '_mpc_')
    assert hasattr(z, '_mpf_')


def test_issue_20733():
    expr = 1/((x - 9)*(x - 8)*(x - 7)*(x - 4)**2*(x - 3)**3*(x - 2))
    assert str(expr.evalf(1, subs={x:1})) == '-4.e-5'
    assert str(expr.evalf(2, subs={x:1})) == '-4.1e-5'
    assert str(expr.evalf(11, subs={x:1})) == '-4.1335978836e-5'
    assert str(expr.evalf(20, subs={x:1})) == '-0.000041335978835978835979'

    expr = Mul(*((x - i) for i in range(2, 1000)))
    assert srepr(expr.evalf(2, subs={x: 1})) == "Float('4.0271e+2561', precision=10)"
    assert srepr(expr.evalf(10, subs={x: 1})) == "Float('4.02790050126e+2561', precision=37)"
    assert srepr(expr.evalf(53, subs={x: 1})) == "Float('4.0279005012722099453824067459760158730668154575647110393e+2561', precision=179)"


def test_issue_28280():
    # This test demonstrates why `evalf_log` needs to specially handle
    # arguments close to 1.If the argument is evaluated directly
    # as `1 + 10**-10` at default precision,it loses the small
    # term and becomes exactly 1. This results in `log(1) -> 0`
    # causing `x > 20` to incorrectly evaluate to False.
    x = 20 + log(1 + S(10)**-10)
    assert x > 20
    y = 20 + log(1 + S(10)**-9)
    assert y > 20