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 Sergey.Kirpichev
Recipients Sergey.Kirpichev, docs@python
Date 2021-03-23.06:30:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616481040.42.0.772549255299.issue43602@roundup.psfhosted.org>
In-reply-to
Content
Commit 82417ca9b2 includes Decimal's in the numbers tower, but only as an implementation of the abstract numbers.Number.  The mentioned reason is "Decimals are not interoperable with floats" (see comments in the numbers.py as well), i.e. there is no lossless conversion (in general, in both directions).

While this seems to be reasonable, there are arguments against:

1) The numbers module docs doesn't assert there should be a lossless conversion for implementations of same abstract type.  (Perhaps, it should.)  This obviously may be assumed for cases, where does exist an exact representation (integers, rationals and so on) - but not for real numbers (or complex), where representations are inexact (unless we consider some subsets of real numbers, e.g. some real finite extension of rationals - I doubt such class can represent numbers.Real).

(Unfortunately, the Scheme distinction of exact/inexact was lost in PEP 3141.)

2) By same reason, I think, neither binary-based multiprecision arithmetics package can represent numbers.Real: i.e. gmpy2.mpfr, mpmath.mpf and so on.  (In general, there is no lossless conversion float's, in both directions.)

3) That might confuse users (why 10-th base arbitrary precision floating point arithmetic can't represent real numbers?).

4) Last, but not least, even some parts of stdlib uses both types in an interoperable way, e.g. Fraction constructor:
    elif isinstance(numerator, (float, Decimal)):
        # Exact conversion
        self._numerator, self._denominator = numerator.as_integer_ratio()
        return self
History
Date User Action Args
2021-03-23 06:30:40Sergey.Kirpichevsetrecipients: + Sergey.Kirpichev, docs@python
2021-03-23 06:30:40Sergey.Kirpichevsetmessageid: <1616481040.42.0.772549255299.issue43602@roundup.psfhosted.org>
2021-03-23 06:30:40Sergey.Kirpichevlinkissue43602 messages
2021-03-23 06:30:39Sergey.Kirpichevcreate