Dumb python questions

Tim Peters tim.one at home.com
Wed Aug 15 08:52:16 CEST 2001


[Paul Rubin]
> ...
> 1) Suppose I have a complex number like a = 3+4j.  How do I get the
> real and imaginary parts separately?

>>> x = 3+4j
>>> x.real
3.0
>>> x.imag
4.0
>>>

> 2) Is there a way I can tell if a value is of an integer type?

>>> import types
>>> isinstance(4, types.IntType)
1
>>>

Etc.

> 3) Are the complex math functions specified to have any particular
>    branch cuts?

No.

>    If they're unspecified, what happens in the actual cmath
>    implementation?

Study the actual cmath implementation -- that's the only docs there are.
cmath wasn't written by a numeric expert, alas.

>    If they're unspecified, I'd like to propose that the Scheme/Common
>    Lisp conventions be adopted in a future version.

While you're at it, propose that they don't suffer spurious overflow or
underflow errors either <wink>.  That is, cmath is the end result of what
volunteers have made it, and indeed that's all it will ever become.  Since
C99 mandates most of the same functions, it may get a dramatic quality boost
almost for free -- provided the C vendors all get around to taking C99
seriously (BTW, I haven't compared the C99 spec to CL's, but if they differ
Python will almost certainly go with C99's, just because Python is coded in
C and cmath volunteers are historically conspicuous by absence).





More information about the Python-list mailing list