New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pow(a,b,c) should accept b<0 #35082
Comments
You should be able to raise integers to negative powers I can come up with a patch for this if it's agreed on |
Logged In: YES Hm. In 2.2a2, currently, pow(a, b, c) for ints a, b, c where b < Assigning to Tim, whose mathematical sensibilities are more |
Logged In: YES Of course I meant (1.0/(a**-b))%c. Sorry! |
Logged In: YES The desire is understandable but this isn't the right way pow(a, b, c) == a**b % c except that the LHS may be very much faster for large "The right way" to do modular arithmetic is to define a |
Logged In: NO Making a 3-arg integer pow return a tiny floating point I'm also enthused about changing / to turn 2/3 into a By the way (off topic), 3-arg pow with ~150 decimal digits |
Logged In: YES Argh. I meant to say I'm NOT enthused about changing /. |
Logged In: YES Hm. There's something to say for making 3-arg pow() only |
Logged In: YES Changed Resolution to None since this was opened again. I still don't like this. It's a wart no matter how you cut The natural way to spell egcd as a library routine would def egcd(aorig, borig):
. """Return (g, i) s.t. g=gcd(aorig, borig) and i*aorig
% borig = g."""
. a, b = aorig, borig
. a1, a2 = 1, 0
. while b:
. q, r = divmod(a, b)
. a1, a2 = a2, a1-q*a2
. a, b = b, r
. if __debug__:
. b1, r = divmod(a - a1*aorig, borig)
. assert r == 0
. assert a1*aorig + b1*borig == a
. return a, a1 |
Logged In: YES The resolution remains Rejected -- apparently selecting I don't like it either -- my suggestion to write a PEP was a Still, it's unclear whether 3-arg pow() makes any sense at |
Logged In: YES If b<0 uses egcd, then pow(4,-1,6) should definitely throw a I'm fine with 3-arg pow throwing an error on non-integer How about continuing to throw an error on b<0, but adding What got me started on this was wanting a modular inverse, |
Logged In: YES Well, speaking as an old fp number-cruncher, mod makes OTOH, I can't doubt that some existing code uses integers >>> pow(3., 500., 7.)
4.0
>>> pow(3, 500, 7)
2
>>> So, as currently implemented, floats in 3-arg pow are 3-arg pow makes clear sense for ints and longs when the |
Logged In: YES OK. Sounds like a good plan: break 3-arg pow() for all |
Logged In: YES Sounds good to me re breaking float pow. It's doing The roundoff errors though don't bother me especially |
Logged In: YES Can we close this now that it's been rejected and we've made |
Logged In: YES That's up to you -- I closed it before, and you opened it |
Logged In: YES I reopened it because there was a different action item then |
For anyone who finds this through google, |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: