Skip to content

Commit

Permalink
Trac #17311: polynomial_real_mpfr_dense.call() accepts only 1 arg
Browse files Browse the repository at this point in the history
burcin mentions in comment 2 of #9769:

The `__call__()` function of RR[x] doesn't conform to the generic
definition. You should be able to give the parameters as a keyword
argument as well. This should be made to work:

{{{
sage: R.<x> = RR[]
sage: (x^2+1)(x=5)
26.0000000000000
}}}

URL: http://trac.sagemath.org/17311
Reported by: rws
Ticket author(s): Ralf Stephan
Reviewer(s): Marc Mezzarobba
  • Loading branch information
Release Manager authored and vbraun committed Jan 23, 2015
2 parents 527c166 + a59fe8c commit 1b7b171
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx
Expand Up @@ -641,7 +641,7 @@ cdef class PolynomialRealDense(Polynomial):
else:
return a * ~a[a.degree()] << min(aval, bval)

def __call__(self, xx):
def __call__(self, *args, **kwds):
"""
EXAMPLES::
Expand Down Expand Up @@ -669,16 +669,29 @@ cdef class PolynomialRealDense(Polynomial):
sage: f = PolynomialRealDense(RR['x'])
sage: f(12)
0.000000000000000
TESTS::
sage: R.<x> = RR[] # :trac:`17311`
sage: (x^2+1)(x=5)
26.0000000000000
"""
if len(args) == 1:
xx = args[0]
else:
return Polynomial.__call__(self, *args, **kwds)

if not PY_TYPE_CHECK(xx, RealNumber):
if self._base_ring.has_coerce_map_from(parent(xx)):
xx = self._base_ring(xx)
else:
return Polynomial.__call__(self, xx)

cdef Py_ssize_t i
cdef mp_rnd_t rnd = self._base_ring.rnd
cdef RealNumber x = <RealNumber>xx
cdef RealNumber res

if (<RealField_class>x._parent).__prec < self._base_ring.__prec:
res = RealNumber(x._parent)
else:
Expand All @@ -704,7 +717,7 @@ cdef class PolynomialRealDense(Polynomial):
mpfr_mul(res.value, res.value, x.value, rnd)
mpfr_add(res.value, res.value, self._coeffs[i], rnd)
return res

def change_ring(self, R):
"""
EXAMPLES::
Expand Down

0 comments on commit 1b7b171

Please sign in to comment.