[issue36228] Add function to complex object

Josh Rosenberg report at bugs.python.org
Thu Mar 7 16:01:02 EST 2019


Josh Rosenberg <shadowranger+python at gmail.com> added the comment:

They already have a .real attribute to extract the real part, which you can call int on. I suspect the lack of support for float/int coercion is intentional; coercing float to int loses precision, but it's still a fundamentally similar value. Implicitly dropping the imaginary component of a complex number isn't just losing precision, it's fundamentally altering the value (in a way that isn't necessarily obvious).

Similarly, there is no meaningful concept of floor/ceil for complex ( https://math.stackexchange.com/q/2095674/332927 ), so implementing it would involve the same data loss as float/int coercion.

complex numbers are complex, and silently ignoring that just makes it easier to write incorrect code. People can do whatever they want with .real explicitly, but we shouldn't be helping them make mistakes.

----------
nosy: +josh.r

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36228>
_______________________________________


More information about the Python-bugs-list mailing list