[Python-Dev] trunc()
Christian Heimes
lists at cheimes.de
Sat Jan 26 23:23:40 CET 2008
Jeffrey Yasskin wrote:
> This interpretation implies that complex should provide __float__() to
> return the non-imaginary portion of a complex number. Is that what you
> intend?
No, please don't. If somebody wants to implement __float__ for complex
numbers please define it as hypot(complex) / sqrt(c.real**2 + c.img**2).
In my opinion float(complex) does do the most sensible thing. It fails
and points the user to abs().
>>> float(complex(1,1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float; use abs(z)
>>> abs(complex(1,1))
1.4142135623730951
More information about the Python-Dev
mailing list