hence "from math import *" overwrites the built-in pow()
function with a function that lacks functionality.
why is it even there?
On 30 Mar 2023, at 10:15, Andreas Eisele <andreas.eisele@gmail.com> wrote: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
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
Thanks in advance for any enlightening comment on this.
Best regards, Andreas
--
https://mail.python.org/mailman/listinfo/python-list
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 unpleasantlysurprised 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
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 unpleasantlysurprised 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
On 30 Mar 2023, at 18:11, Barry Scott <barry@barrys-emacs.org> wrote:
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 theOn 30 Mar 2023, at 10:15, Andreas Eisele <andreas.eisele@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
Maybe math.pow() aways using IEEE 754(?) float point via the C runtime math routines.
pow() will give int answer if called with int args.
Barry
Thanks in advance for any enlightening comment on this.
Best regards, Andreas
--
https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list
On 3/30/2023 5:15 AM, Andreas Eisele wrote:
[...] 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. [...]
Not an answer to your question, but it's better not to use "import *".
It's usually better to import just the names you actually need.
Either import the things you need explicitly: "from math import sin,
cos, exp" (for example).
Or a plain import: "import math" combined with "math.sin", "math.cos".
Or use an abbreviation: "import math as m" combined with "m.sin", "m.cos".
81.0from math import *
pow(3, 4)
81del pow
pow(3, 4)
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 unpleasantlysurprised 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
On Thu, 30 Mar 2023 at 17:31, Andreas Eisele <andreas.eisele@gmail.com> wrote: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
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
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.
On 30 Mar 2023, at 22:30, Chris Angelico <rosuav@gmail.com> wrote: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
On Fri, 31 Mar 2023 at 08:13, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote:
On Thu, 30 Mar 2023 at 17:31, Andreas Eisele <andreas.eisele@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
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.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
On 30 Mar 2023, at 22:30, Chris Angelico <rosuav@gmail.com> wrote:
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.
On 2023-03-31 07:39:25 +0100, Barry wrote:
On 30 Mar 2023, at 22:30, Chris Angelico <rosuav@gmail.com> wrote:
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.
Well, that's the first line in the docs:
| This module provides access to the mathematical functions defined by
| the C standard.
Of course a Python programmer may not necessarily know what mathematical functions the C standard defines or even what C is.
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 unpleasantlysurprised 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
Thanks in advance for any enlightening comment on this.
Best regards, Andreas
BTW, there is another difference: built-in pow() deals with complex arguments, while functions in math won't accept them at all.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 62:00:11 |
Calls: | 6,712 |
Files: | 12,244 |
Messages: | 5,355,894 |