3-arg float pow()
Tim Peters
tim.one at home.com
Wed Sep 5 02:37:09 EDT 2001
>> TypeError: 3rd argument to floating pow() must be None
[Gareth McCaughan]
> Can I put in a request for "or omitted", or something of
> the kind, to go on the end of that error message?
>> TypeError: integer pow() arg 3 must not be specified when arg 2 is < 0
> And for the messages in those two cases to be made more
> consistent?
Sure! These were changed, to
pow() 3rd argument cannot be 0
pow() 2nd argument cannot be negative when 3rd argument specified
pow() 3rd argument not allowed unless all other arguments are integers
> ...
> Oh, one other thing. Giving a third argument of 0 should
> probably be equivalent to giving a third argument of None
Sorry, not a chance. You can make up any argument you want, but it remains
100x more likely that someone doing
pow(i, j, k)
when k is 0 has made an error than that they're trying to exploit some
clever argument, of which, as you say:
> ...
> I don't think any programming language agrees with me...
> (Rationale:
>
> - "x % y" means "the smallest thing that's congruent to x
> modulo y", for some interpretation of "smallest".
Not in Python. x % y means divmod(x, y)[1] in Python, and divmod(x, y) is a
pair (q, r) such that q*y + r == x and abs(r) < abs(y) (and the strict
inequality there is part of what "smallest" means in Python).
> - "x == z mod y" means "y divides x-z", which means "x-z
> is a multiple of y".
>
> - When y=0, this reduces to "x=z".
>
> - The smallest -- and indeed the only -- thing that's
> congruent to x mod 0 is therefore x itself.)
I understand the argument. Still no chance <wink>. Forget that it violates
abs(r) < abs(y) whenever abs(x) >= abs(y): of what *use* is this? I can't
imagine a real algorithm where a single line
pow(x, y, z)
*sometimes* wants to do a modular pow and sometimes not -- and even if I
could, I can get that now via setting z to None.
python-tries-not-to-hide-probable-errors-ly y'rs - tim
More information about the Python-list
mailing list