Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit c47dbd4

Browse files
committed
Fix Trac #17328 again in a better way
1 parent 7265989 commit c47dbd4

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/sage/functions/other.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def _evalf_(self, x, y, parent=None, algorithm=None):
936936
sage: incomplete_gamma(RR(-1), RR(-1))
937937
-0.823164012103109 + 3.14159265358979*I
938938
sage: incomplete_gamma(-1, float(-log(3))) - incomplete_gamma(-1, float(-log(2)))
939-
1.27309721644711
939+
(1.2730972164471142+0j)
940940
941941
Check that :trac:`17130` is fixed::
942942
@@ -945,13 +945,27 @@ def _evalf_(self, x, y, parent=None, algorithm=None):
945945
sage: type(r)
946946
<type 'float'>
947947
"""
948-
if parent is None:
949-
parent = s_parent(x)
950-
try:
951-
prec = parent.precision()
952-
except Exception:
948+
R = parent or s_parent(x)
949+
# C is the complex version of R
950+
# prec is the precision of R
951+
if R is float:
953952
prec = 53
954-
return parent(ComplexField(prec)(x).gamma_inc(y))
953+
C = complex
954+
else:
955+
try:
956+
prec = R.precision()
957+
except AttributeError:
958+
prec = 53
959+
try:
960+
C = R.complex_field()
961+
except AttributeError:
962+
C = R
963+
v = ComplexField(prec)(x).gamma_inc(y)
964+
if v.is_real():
965+
return R(v)
966+
else:
967+
return C(v)
968+
955969

956970
# synonym.
957971
incomplete_gamma = gamma_inc=Function_gamma_inc()

0 commit comments

Comments
 (0)