On Wed, Sep 14, 2011 at 7:57 PM, Anton Sherwood <bro...@pobox.com> wrote:
> Is there a function inverse to complex(x,y),
> such that (x,y) == ReIm(complex(x,y)) ?
>
> I could obviously write one -- def ReIm(z): return (z.real,z.imag) -- but
> presumably a library function if it exists would be speedier.

For Sage's complex types, you can do.

sage: a = CDF(1,2)
sage: a
1.0 + 2.0*I
sage: x, y = a
sage: x
1.0
sage: y
2.0

(Works for CC as well.) Otherwise, z.real, z.imag is probably going to
be as fast as you can get, and there's no need to define a function,
you could just write

sage: a = complex(3,4)
sage: x, y = a.real, a.imag

- Robert

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to