<br><div class="gmail_quote">On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
&gt;&gt;&gt; pow(20, 0.3333333)<br>
2.7144173455393048<br>
&gt;&gt;&gt; pow(-20, 0.3333333)<br>
Traceback (most recent call last):<br>
 &nbsp;File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>
ValueError: negative number cannot be raised to a fractional power<br>
&gt;&gt;&gt; -20**0.3333333<br>
-2.7144173455393048<br>
&gt;&gt;&gt;<br>
<br>
So the exponentiation operator seems happy but pow isn&#39;t.<br>
<br>
Very strange and potentially a bug in pow()?<br>
Unless someone knows a reason for it?</blockquote><div><br><br>I think you&#39;re confusing the order of operations.<br><br>math.pow(-20, (1.0/3.0)) and -20**(1.0/3.0) are not equivalent<br><br>Whereas, as john mentioned, -20**(1.0/3.0) is actually -(20**(1.0/3.0)), math.pow(-20, (1.0/3.0)) is (-20)**(1.0/3.0)<br>
</div></div><br>The behavior of ** is appropriate since <a href="http://docs.python.org/ref/summary.html">http://docs.python.org/ref/summary.html</a> shows that exponentiation has higher precedence over positive, negative.<br>
<br>Also, I found this from <a href="http://www.python.org/download/releases/2.0/">http://www.python.org/download/releases/2.0/</a>:<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<i>Raise ZeroDivisionError when raising zero to a negative number,
  e.g. 0.0 ** -2.0.  Note that math.pow is unrelated to the builtin
  power operator and the result of math.pow(0.0, -2.0) will vary by
  platform.  On Linux, it raises a ValueError.</i></blockquote><div><br>which is related to why some people would get nan and others a ValueError.<br><br>And, just to clarify (although i doubt there was any confusion over it),&nbsp;&nbsp; -20**(1/3) = -1 * (20**0) = -1 due to integer division magic.<br>
</div>