On Sun, Jul 24, 2011 at 5:47 PM, john_perry_usm <[email protected]> wrote:
> I want to declare c to be of the type defined by the class Rational.
> I'm sure this is easy, but what I want to do is this:
>
> from sage.rings.rational import Rational
> cdef Rational c
>
> but that doesn't work. Neither does cimport (which I found in a file
> somewhere, albeit commented out, and now I know why).
>
Actually,
from sage.rings.rational cimport Rational
*does* work, but you have to put it in the right place. As an illustration,
try this in the notebook:
%cython
from sage.rings.rational cimport Rational
def f(Rational c, s):
cdef Rational dummy = Rational('2/3') # just for illustrative purposes
print dummy
mpq_set_str(c.value, s, 10)
Then in the next cell put this:
c = 8/7
f(c, '5/3')
print c
-- William
>
> regards
> john perry
>
> --
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>
--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org