[Python-ideas] isinstance(Decimal(), Real) -> False?

Draic Kin drekin at gmail.com
Wed Aug 28 12:48:02 CEST 2013


On Wed, Aug 28, 2013 at 12:30 PM, Vernon D. Cole <vernondcole at gmail.com>wrote:

> Darn right it should return False.  Given the principle of least surprise
> (and my prejudices built up over 40 years as a computer programmer) I would
> expect that decimal.Decimal data would be stored internally as some form of
> decimal data, and would store into a database as such.  It would be
> expected to be in a fixed point format.  Real, on the other hand, I would
> expect to be stored as an IEEE double precision floating point number, or
> something like that.
>   I don't care whether a fixed point decimal number might be defined by a
> mathematician as "real" -- I care whether it can be processed by an FPU,
> and whether it will loose precision in large financial calculations.
>
>
For the same reason, I could think that isinstance(Decimal, Rational) ->
True and issubclass(Rational, Real) -> False. It's more about exact vs.
non-exact computations which is orthogonal to number hierarchy. Maybe there
should be some ExactNumber abstract base class and some convention that
exact shouldn't coerce with non-exact. So Decimal + float should raise an
exception even if both would be subclasses of Real (and Decimal even of
Rational). Or maybe it would be enough if there were just non-exact
variants of Real and Complex since non-exactness if just issue of them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130828/05ea2118/attachment.html>


More information about the Python-ideas mailing list