3-arg float pow()

David C. Ullrich ullrich at math.okstate.edu
Mon Sep 3 10:05:29 EDT 2001


On Mon, 3 Sep 2001 03:05:53 -0400, "Tim Peters" <tim.one at home.com>
wrote:

>Python's builtin 3-argument pow() exists because, e.g.,
>
>>>> pow(3L, 500, 7)
>2L
>>>>
>
>can be done very much faster, and with much less memory, than
>
>>>> 3L**500 % 7
>2L
>>>>
>
>There isn't any compelling use I know of for 3-arg pow() given float
>arguments, though, and what you get back is a platform-dependent accident:
>
>>>> pow(3., 500., 7.)
>4.0
>>>>
>
>You may get some other integer there, or an Infinity or a NaN, depending on
>the Python release, and the compiler used to build Python, and the
>configuration of your libm.  That example was done under CVS 2.2a2+ on
>Windows; here's the same thing but under 2.2.1:
>
>>>> pow(3., 500., 7.)
>0.0
>>>>
>
>Since 3-argument float pow() *appears* to be at best useless, I'm taking it
>away in 2.2a3, unless someone can testify to a reasonable use case that's
>actually used.

Please note that this is not a comment on what's useful or not, I 
wouldn't know about that. Just curious:

Seems like pow(3., 500., 7.) can't possibly do anything except just
3.**500. % 7(???), hence the random nature of the result and the utter
uselessness. When you say you're taking away "float pow()" it's not
clear to me exactly what's going away. 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. So
pow(3., 500, 7.) would be legal, and also would be computed 
efficiently using whatever you call the repeated-squaring thing.

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...

>more-trouble-than-it's-worth-if-it-isn't-worth-anything-ly y'rs  - tim
>
>


David C. Ullrich



More information about the Python-list mailing list