3-arg float pow()

Paul Rubin phr-n2001 at nightsong.com
Mon Sep 3 18:11:34 EDT 2001


"Tim Peters" <tim.one at home.com> writes:
> > A possibility that springs to mind would be a pow() that allows
> > any type for the first and third arguments but requires a positive
> > integer for the exponent.
> 
> That would disallow the pow(2, -5) example above, and we don't want to
> disallow that.

That doesn't seem so bad.  2**-5 is already not allowed.

> > So pow(3., 500, 7.) would be legal, and also would be computed
> > efficiently using whatever you call the repeated-squaring thing.
> 
> I would only care about this if it's *useful*, but (outside of the Python
> test suite) I've never seen 3-argument pow with a non-None 3rd argument used
> except when the first two arguments were of integer types.  Change the
> example to pow(3.1, 500, 7.), and the result is doomed to be gibberish no
> matter how implemented (short of heroic efforts that would bloat the code
> for something never used -- but this isn't Common Lisp <wink>).

Part of this discussion would be simpler if the artificial example
were different--what should pow(3., 50000, 7.) do?  What about pow(3.,
50000., 7.)?  I think it's entirely appropriate for 3-arg pow to only
work if all 3 args are integers.


> > Not that I actually see any use for this with floats, but I _do_
> > use a Pow() that works exactly like this for powers of matricies
> > and things...
> 
> That's fine, but seems a different issue.

I don't have ANY reasonable suggestions for what 3-arg pow of matrices
should do except throw errors.



More information about the Python-list mailing list