This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author oscarbenjamin
Recipients Sergey.Kirpichev, docs@python, mark.dickinson, oscarbenjamin, rhettinger, tim.peters
Date 2021-04-16.11:08:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618571285.67.0.911820993843.issue43602@roundup.psfhosted.org>
In-reply-to
Content
I've never found numbers.Real/Complex to be useful. The purpose of the ABCs should be that they enable you to write code that works for instances of any subclass but in practice writing good floating point code requires knowing something e.g. the base, precision, max exponent etc of the type. Also many implementations like Decimal have contexts and rounding control etc that need to be used and the ABC gives no way to know that or to do anything with it.

The main thing that is useful about the Rational/Integer ABCs is that they define the numerator and denominator attributes which makes different implementations interoperable by providing exact conversion. If Real was presumed to represent some kind of floating point type then an analogous property/method would be something that can deconstruct the object in an exact way like:

mantissa, base, exponent = deconstruct(real)

You would also need a way to handle nan, inf etc. Note that as_integer_ratio() is not suitable because it could generate enormous integers unnecessarily e.g. Decimal('1E+100000000').as_integer_ratio().

Instead the Real ABC only defines conversion to float. That's useful in the sense that you can write code for float and pass in some other floating point type and have everything reduce to float. You don't need an ABC for that though because __float__ does everything. In practice most alternate "real" number implementations exist precisely to be better than float in some way by either having greater range/precision or a different base but anything written for the Real ABC is essentially reduced to float as a lowest common (inexact) denominator.
History
Date User Action Args
2021-04-16 11:08:05oscarbenjaminsetrecipients: + oscarbenjamin, tim.peters, rhettinger, mark.dickinson, docs@python, Sergey.Kirpichev
2021-04-16 11:08:05oscarbenjaminsetmessageid: <1618571285.67.0.911820993843.issue43602@roundup.psfhosted.org>
2021-04-16 11:08:05oscarbenjaminlinkissue43602 messages
2021-04-16 11:08:05oscarbenjamincreate