complex numbers
Robert Kern
rkern at ucsd.edu
Wed Jan 12 13:25:12 EST 2005
It's me wrote:
> "Robert Kern" <rkern at ucsd.edu> wrote in message
> news:cs1mp9$sg9$1 at news1.ucsd.edu...
>
>>That's *it*.
>
>
> So, how would you overload an operator to do:
>
> With native complex support:
>
> def twice(a):
> return 2*a
>
> print twice(3+4j), twice(2), twice("abc")
>
> Let's presume for a moment that complex is *not* a native data type in
> Python. How would we implement the above - cleanly?
The way it's implemented now. See the file Object/complexobject.c for
details. Numeric operations on ints, longs, floats, and complex numbers
are all implemented using operator overloading.
There's nothing special about the complex object. One can even remove it
from the language quite easily. Some of the embedded versions of Python
have in fact done so.
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list