On May 4, 2010, at 8:21 AM, Jason Grout <[email protected]> wrote:
> Right now, we have the following behavior:
>
> sage: float(CC(1.0))
> 1.0
>
>
> sage: float(CDF(1.0))
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
>
> /home/jason/<ipython console> in <module>()
>
> /home/jason/sage/local/lib/python2.6/site-packages/sage/rings/complex_double.so
> in sage.rings.complex_double.ComplexDoubleElement.__float__
> (sage/rings/complex_double.c:6532)()
>
> TypeError: can't convert complex to float; use abs(z)
>
>
> sage: float(complex(1.0))
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
>
> /home/jason/<ipython console> in <module>()
>
> TypeError: can't convert complex to float
>
>
> Does anyone object to me changing float(CDF(1.0)) to behave like
> float(CC(1.0)) (i.e., a float conversion will succeed if the imaginary part
> is 0). Note that this will make CDF and the python complex type have
> different behaviors.
I think I wrote the original code for this, and I am ok with the change you
suggest, since our policy on explicit coercions is to make them work when they
make (some) mathematical sense.
>
> Also note that this will partially match the numpy complex type (which
> apparently just returns the real part of the number on conversion to float):
>
> sage: float(numpy.complex128(1.0))
> 1.0
> sage: float(numpy.complex128(1.0+2j))
> 1.0
That is truly evil.
William
>
> Thanks,
>
> Jason
>
> --
> To post to this group, send an email to [email protected]
> To unsubscribe from this group, send an email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org