3-arg float pow()

Tim Peters tim.one at home.com
Thu Sep 6 01:55:59 EDT 2001


[Tim]
>> pow() 3rd argument not allowed unless all other arguments are integers

[Gareth McCaughan]
> I agree with John Baxter that "all" in the third of these
> seems a little odd.  Delete the second occurrence of the
> substring " all" and it will improve. :-)

I agree too, but picked on "other " instead of " all", because, e.g.,

    pow(2, 3, 1.8)

isn't allowed either, and then

    pow() 3rd argument not allowed unless other arguments are integers

doesn't really make sense ("the other" (non-3rd) args *are* ints), but

    pow() 3rd argument not allowed unless all arguments are integers

does, and for all seven disallowed signatures from [integer, float]**3.

...

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

> That isn't a complete description of what Python does
> (it couldn't be, since it doesn't determine the answer
> uniquely),

Sure -- it only brought out enough to show where x%0 == x would violate what
Python currently guarantees (that abs(x%y) < abs(y)).

> and I assure you that Python's behaviour fits what I meant by "some
> interpretation of `smallest'", though perhaps I was too terse there.

Which is why I assured you in turn that it doesn't fit "what 'smallest'
means in Python".  Guido had the novel of idea of tying "smallest" to the
meaning of the "<" operator <wink>.

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

> I bet number theorists would sometimes want that.

They already can:  set z to None.  They surely don't need two ways to spell
that.

> But,really, I agree with you. (I'd still *prefer* things the
> way I suggested, but I don't really think Python should
> change to accommodate this preference.)

Then this is indeed a lucky day for both of us <wink>.





More information about the Python-list mailing list