pow() & modulo QUESTION

MRAB python at mrabarnett.plus.com
Fri Apr 1 21:04:22 EDT 2016


On 2016-04-02 00:08, vaulhausen at gmail.com wrote:
> Having trouble performing the pow() function with
> real numbers.
>
> I want to also take a modulo value....
>
> Weirdly, this works fine ;
>
> pow(2,6000,400) = 176
>
> However, this returns an error ;
>
> pow(1.4142, 6000, 400)
>
> I have tried also the math.pow() function but it doesnt
> work either..... can any one give me a hand with this?
>
The 2-argument form pow(x, y) is equivalent to x ** y.

When working with integers, there's a more efficient way of calculating 
x ** y % z, so pow provides that with the 3-argument form pow(x, y, z).

Of course, you could argue that pow should allow the 3-argument for even 
with floats, but it wouldn't be any faster than x ** y % z.




More information about the Python-list mailing list