[Python-Dev] return type of complex (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sun Oct 21 12:31:31 CEST 2012
- Previous message: [Python-Dev] return type of __complex__
- Next message: [Python-Dev] return type of __complex__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Oct 21, 2012 at 3:06 PM, Devin Jeanpierre <jeanpierreda at gmail.com> wrote:
On Sat, Oct 20, 2012 at 10:57 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
PEP 3141 is indeed the driver for these changes, and it's based on the Python 3.x numeric tower consisting of strict supersets: Complex > Real > Rational > Integral Pedant mode: That numeric tower is wrong as it applies to Python -- we have some rational types that can represent some numbers that can't be represented by our complex and """real""" types. >>> int(float(10100)) == 10100 False (Also, floats aren't reals and no computer can store any number that is not rational and we should stop pretending they can. (Complex numbers get a free pass because "complex numbers with rational real and imaginary parts" is not a memorable name for a type.))
Floats are not rational either, since they allow infinities and NaN as values. Both float and Decimal are approximations to the Real number set, as int and Fraction are approximations to the Integer and Rational sets. In all cases, they cannot express the full scope of the associated numeric concept, because they're limited by their physical representations as bit patterns inside the computer (while that limit is technically available memory for the unbounded representations, the practical limit is lower than that if you want vaguely reasonable running times for arbitrary arithmetic operations).
As far as the conversion operators go, I don't recall there being any discussion one way or the other - the question simply never came up, presumably because all code tested already returned complex objects from complex.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] return type of __complex__
- Next message: [Python-Dev] return type of __complex__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]