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

Commit

Permalink
25456: more generic real ball initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
videlec committed Jun 1, 2018
1 parent a1ec959 commit 2d4ff24
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/sage/rings/real_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class RealBallField(UniqueRepresentation, Field):
sage: RBF(x)
Traceback (most recent call last):
...
TypeError: unable to convert x to a RealBall
TypeError: unable to simplify to a real interval approximation
Various symbolic constants can be converted without going through real
intervals. (This is faster and yields tighter error bounds.) ::
Expand All @@ -517,12 +517,9 @@ class RealBallField(UniqueRepresentation, Field):
return mid.operator()(*[self(operand) for operand in mid.operands()])
except (AttributeError, TypeError):
pass
try:
mid = RealIntervalField(self._prec)(mid)
return self.element_class(self, mid, rad)
except TypeError:
pass
raise TypeError("unable to convert {!r} to a RealBall".format(mid))

mid = RealIntervalField(self._prec)(mid)
return self.element_class(self, mid, rad)

def _repr_option(self, key):
"""
Expand Down Expand Up @@ -1326,6 +1323,15 @@ cdef class RealBall(RingElement):
Traceback (most recent call last):
...
TypeError: no canonical coercion...
Check that :trac:`25456` is fixed::
sage: RBF(5,0)
5.000000000000000
sage: RBF(5.,0)
5.000000000000000
sage: RBF(5.,1)
[+/- 6.01]
"""
cdef fmpz_t tmpz
cdef fmpq_t tmpq
Expand Down Expand Up @@ -1409,15 +1415,18 @@ cdef class RealBall(RingElement):

if rad is not None:
mag_init(tmpm)
if isinstance(rad, RealNumber):
if isinstance(rad, float):
mag_set_d(tmpm, PyFloat_AS_DOUBLE(rad))

else:
if not isinstance(rad, RealNumber):
rad = RealField(53, False, "RNDA")(rad)

arf_init(tmpr)
arf_set_mpfr(tmpr, (<RealNumber> rad).value)
arf_get_mag(tmpm, tmpr)
arf_clear(tmpr)
elif isinstance(rad, float):
mag_set_d(tmpm, PyFloat_AS_DOUBLE(rad))
else:
raise TypeError("rad should be a RealNumber or a Python float")

mag_add(arb_radref(self.value), arb_radref(self.value), tmpm)
mag_clear(tmpm)

Expand Down

0 comments on commit 2d4ff24

Please sign in to comment.