power TypeErrors
Michael Hudson
mwh at python.net
Wed Nov 6 05:36:33 EST 2002
bokr at oz.net (Bengt Richter) writes:
> But this makes wonder about working with complex numbers, where
> name bindings might be to plain real negatives as well as complex
> numbers (as easy to do as binding to integers and floats, which makes
> for the '/' problem) yet you might want the same for
> >>> a = -4.0+0j
> >>> b = -4.0
> >>> a ** 0.5
> (1.2246063538223773e-016+2j)
> >>> b ** 0.5
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ValueError: negative number cannot be raised to a fractional power
>
> It seems like a problem analogous to the true division problem,
> except that fewer people expect complex results.
Does anyone actually use complex numbers in Python? I guess the
numeric folks might.
complex ** complex is multi-valued, of course. But so's int ** float,
so I guess people can live with that.
> I wouldn't want complex results all the time, but I can see wanting
> to run that way in a limited context.
It's a bit odd that there's no cmath.pow().
> Which comes down again to whether there should be some kind of general
> mechanism to control such modes of operation within scopes such as
> function bodies or statement suites (indented blocks).
Would be nice, but sounds hard.
Cheers,
M.
--
Premature optimization is the root of all evil.
-- Donald E. Knuth, Structured Programming with goto Statements
More information about the Python-list
mailing list