built-in pow() vs. math.pow()
Barry
barry at barrys-emacs.org
Fri Mar 31 02:39:25 EDT 2023
> On 30 Mar 2023, at 22:30, Chris Angelico <rosuav at gmail.com> wrote:
>
> On Fri, 31 Mar 2023 at 08:13, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
>>
>>> On Thu, 30 Mar 2023 at 17:31, Andreas Eisele <andreas.eisele at gmail.com> wrote:
>>>
>>> I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there?
>>
>> It is useful for when you want the pure floating point power which has
>> an approximately fixed computational cost (unlike integer powers).
>> Perhaps it would have been better if it was named fpow similar to fsum
>> vs sum.
>>
>
> It's called math.pow. That on its own should be a strong indication
> that it's designed to work with floats.
So long as you know that the math module is provided to give access the C math.h functions.
Barry
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list