[Python-ideas] isinstance(Decimal(), Real) -> False?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Thu Aug 29 16:43:26 CEST 2013
On 29 August 2013 15:06, Draic Kin <drekin at gmail.com> wrote:
>
> To answer your original question, according to comments in sources of
> decimal.py and numbers.py, Decimal shouldn't be subclass of Real since it
> doesn't interoperate with floats and different subclasses of Real should
> interoperate. From my point of view, if floats weren't more common that
> decimals, one could turn the same argument around: Decimal subclasses Real
> but float doesn't since it doesn't interoperate with Decimal. Maybe they
> should interoperate and as you pointed out, Decimal is more robust in
> handling errors so maybe float + Decimal should yield Decimal. Then Decimal
> could be integrated to the number hierarchy.
At least the explicit Decimal(Fraction) should work (setting the
Inexact flag as necessary). Decimal * Fraction etc. should also work.
It's not trivial to ensure that e.g. Decimal*Fraction gives a
correctly rounded Decimal result.
> Maybe there is still this problem: what would Decimal + complex return?
I guess it would have to be a complex. It would be good if there were
a ComplexDecimal but it's not so important as getting the real numbers
right.
Oscar
More information about the Python-ideas
mailing list