Python's numeric tower

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Jun 15 20:38:46 EDT 2014


On Sun, 15 Jun 2014 13:28:44 -0400, Roy Smith wrote:

> In article <539dbcbe$0$29988$c3e8da3$5496439d at news.astraweb.com>,
>  Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> 
>> On Sun, 15 Jun 2014 01:22:50 -0600, Ian Kelly wrote:
>> 
>> > On Sat, Jun 14, 2014 at 8:51 PM, Steven D'Aprano
>> > <steve+comp.lang.python at pearwood.info> wrote:
>> >> Does anyone know any examples of values or types from the standard
>> >> library or well-known third-party libraries which satisfies
>> >> isinstance(a, numbers.Number) but not isinstance(a,
>> >> numbers.Complex)?
>> > 
>> >>>> issubclass(decimal.Decimal, numbers.Number)
>> > True
>> >>>> issubclass(decimal.Decimal, numbers.Complex)
>> > False
>> 
>> Well, that surprises and disappoints me, but thank you for the answer.
> 
> Why would you expect Decimal to be a subclass of Complex?


py> from decimal import Decimal
py> Decimal("1.5").imag
Decimal('0')


Mathematically, ℂ (complex) is a superset of ℝ (real), and Decimals are a 
kind of real(ish) number, like float:

py> from numbers import Complex
py> isinstance(1.5, Complex)
True


But then I suppose it is understandable that Decimal doesn't support the 
full range of complex arithmetic.


-- 
Steven



More information about the Python-list mailing list