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

Commit

Permalink
23077: Fix complex handling of libs/pynac/py_float()
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed May 25, 2017
1 parent c011cfa commit cb88513
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/sage/functions/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ class Function_Bessel_I(BuiltinFunction):
sage: a = bessel_I(pi, bessel_I(1, I))
sage: N(a, digits=20)
0.00026073272117205890528 - 0.0011528954889080572266*I
0.00026073272117205890524 - 0.0011528954889080572268*I
sage: f = bessel_I(2, x)
sage: f.diff(x)
Expand Down Expand Up @@ -876,7 +876,7 @@ class Function_Bessel_K(BuiltinFunction):
sage: a = bessel_K(pi, bessel_K(1, I)); a
bessel_K(pi, bessel_K(1, I))
sage: N(a, digits=20)
3.8507583115005220157 + 0.068528298579883425792*I
3.8507583115005220156 + 0.068528298579883425456*I
sage: f = bessel_K(2, x)
sage: f.diff(x)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/hypergeometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
sage: hypergeometric([1, 2, 3], [4, 5, 6], 1/2).n(digits=30)
1.02573619590133865036584139535
sage: hypergeometric([5 - 3*I], [3/2, 2 + I, sqrt(2)], 4 + I).n()
5.52605111678805 - 7.86331357527544*I
5.52605111678803 - 7.86331357527540*I
sage: hypergeometric((10, 10), (50,), 2.)
-1705.75733163554 - 356.749986056024*I
Expand Down
8 changes: 7 additions & 1 deletion src/sage/libs/pynac/pynac.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,13 @@ cdef py_float(n, PyObject* kwds):
<type 'sage.rings.complex_number.ComplexNumber'>
"""
if kwds is not NULL:
return (<object>kwds)['parent'](n)
try:
return (<object>kwds)['parent'](n)
except TypeError:
try:
return (<object>kwds)['parent'].complex_field()(n)
except AttributeError:
return CC(n)
else:
try:
return RR(n)
Expand Down
6 changes: 2 additions & 4 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1385,11 +1385,9 @@ cdef class Expression(CommutativeRingElement):
0.6666666666666666
sage: float(sqrt(SR(2)))
1.4142135623730951
sage: float(x^2 + 1)
Traceback (most recent call last):
...
TypeError: unable to simplify to float approximation
sage: float(SR(RIF(2)))
2.0
sage: float(x^2 + 1)
Traceback (most recent call last):
...
TypeError: unable to simplify to float approximation
Expand Down

0 comments on commit cb88513

Please sign in to comment.