pow function

   5013   3   0
User Avatar
Member
30 posts
Joined: July 2010
Offline
The pow function raise error with non integer exponent. how could I compute something like pow(x,0.3)
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
It seems to work fine for me. Can you provide an example?
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Staff
2592 posts
Joined: July 2005
Offline
mosari
The pow function raise error with non integer exponent. how could I compute something like pow(x,0.3)


>>> import math
>>> math.pow(3, .3)
1.3903891703159093
>>> math.pow(-3, .3)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ValueError: math domain error

When you have a rational exponent (i.e. a non integer), the expression is equivalent to… well, let's see how my ASCII art is:

(m/n) n —–
a = \ / (m)
\/ a


That is, the nth root of (pow(a, m)).

Since radicals are ill defined when the base is negative, you end up
with imaginary results. Which might prove difficult.

For example: pow(-5, 0.5) == sqrt(-5)

I assume this is your problem?
User Avatar
Member
30 posts
Joined: July 2010
Offline
Yes this was the problem. thank you for your replies
  • Quick Links