Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C++ <strike><a href="http://en.cppreference.com/w/cpp/numeric/complex/pow">The result of pow(0, 0)</a></strike> the result is basically implementation defined behavior since mathematically we have a contradictory situation where <code>N^0</code> should always be <code>1</code> but <code>0^N</code> should always be <code>0</code> for <code>N &gt; 0</code>, so you should have no expectations mathematically as to the result of this either. This <a href="http://community.wolframalpha.com/viewtopic.php?f=35&amp;t=11131">Wolfram Alpha</a> forum posts goes into a bit more details.</p> <p>Although having <code>pow(0,0)</code> result in <code>1</code> is useful for many applications as the <a href="http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf"> Rationale for International Standard—Programming Languages—C</a> states in the section covering <em>IEC 60559 floating-point arithmetic</em> support:</p> <blockquote> <p>Generally, C99 eschews a NaN result where a numerical value is useful. [...] The results of pow(∞,0) and pow(0,0) are both 1, because there are applications that can exploit this definition. For example, if x(p) and y(p) are any analytic functions that become zero at p = a, then pow(x,y), which equals exp(y*log(x)), approaches 1 as p approaches a.</p> </blockquote> <p><B>Update C++</b></p> <p>As leemes correctly pointed out I originally linked to the reference for the <em>complex</em> version of <em>pow</em> while the <a href="http://en.cppreference.com/w/cpp/numeric/math/pow">non-complex</a> version claims it is <em>domain error</em> the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf">draft C++ standard</a> falls back to the <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf">draft C standard</a> and both <em>C99</em> and <em>C11</em> in section <code>7.12.7.4</code> <em>The pow functions</em> paragraph <em>2</em> says (<em>emphasis mine</em>):</p> <blockquote> <p>[...]A domain error <strong>may occur</strong> if x is zero and y is zero.[...]</p> </blockquote> <p>which as far as I can tell means this behavior is <a href="http://en.wikipedia.org/wiki/Unspecified_behavior">unspecified behavior</a> Winding back a bit section <code>7.12.1</code> <em>Treatment of error conditions</em> says:</p> <blockquote> <p>[...]a domain error occurs if an input argument is outside the domain over which the mathematical function is defined.[...] On a domain error, the function returns an implementation-defined value; if the integer expression math_errhandling &amp; MATH_ERRNO is nonzero, the integer expression errno acquires the value EDOM; [...]</p> </blockquote> <p>So if there was a <em>domain error</em> then this would be <em>implementation defined behavior</em> but in both the latest versions of <code>gcc</code> and <code>clang</code> the value of <code>errno</code> is <code>0</code> so it is not a <em>domain error</em> for those compilers.</p> <p><B>Update Javascript</B></p> <p>For <em>Javascript</em> the <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript® Language Specification</a> in section <code>15.8</code> <em>The Math Object</em> under <code>15.8.2.13</code> <em>pow (x, y)</em> says amongst other conditions that: </p> <blockquote> <p>If y is +0, the result is 1, even if x is NaN.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload