if isinstance(result, (mpmath.mpc, mpmath.mpf)):
if mpmath.isinf(result) and isinstance(result, mpmath.mpc):
result = Symbol("ComplexInfinity")
elif mpmath.isinf(result) and result > 0:
result = Expression("DirectedInfinity", Integer(1))
elif mpmath.isinf(result) and result < 0:
result = Expression("DirectedInfinity", Integer(-1))
elif mpmath.isnan(result):
result = Symbol("Indeterminate")
else:
result = Number.from_mpmath(result)