summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fmath%2Fpow.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/numeric%2Fmath%2Fpow.html')
-rw-r--r--devdocs/c/numeric%2Fmath%2Fpow.html122
1 files changed, 122 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Fmath%2Fpow.html b/devdocs/c/numeric%2Fmath%2Fpow.html
new file mode 100644
index 00000000..c0edd34b
--- /dev/null
+++ b/devdocs/c/numeric%2Fmath%2Fpow.html
@@ -0,0 +1,122 @@
+ <h1 id="firstHeading" class="firstHeading">pow, powf, powl</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;math.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float powf( float base, float exponent );</pre>
+</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl"> <td> <pre data-language="c">double pow( double base, double exponent );</pre>
+</td> <td> (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long double powl( long double base, long double exponent );</pre>
+</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;tgmath.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define pow( base, exponent )</pre>
+</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <div class="t-li1">
+<span class="t-li">1-3)</span> Computes the value of <code>base</code> raised to the power <code>exponent</code>.</div> <div class="t-li1">
+<span class="t-li">4)</span> Type-generic macro: If any argument has type <code>long double</code>, <code>powl</code> is called. Otherwise, if any argument has integer type or has type <code>double</code>, <code>pow</code> is called. Otherwise, <code>powf</code> is called. If at least one argument is complex or imaginary, then the macro invokes the corresponding complex function (<code><a href="http://en.cppreference.com/w/c/numeric/complex/cpow"><span class="kw775">cpowf</span></a></code>, <code><a href="http://en.cppreference.com/w/c/numeric/complex/cpow"><span class="kw774">cpow</span></a></code>, <code><a href="http://en.cppreference.com/w/c/numeric/complex/cpow"><span class="kw776">cpowl</span></a></code>).</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> base </td> <td> - </td> <td> base as floating point value </td>
+</tr> <tr class="t-par"> <td> exponent </td> <td> - </td> <td> exponent as floating point value </td>
+</tr>
+</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, <code>base</code> raised to the power of <code>exponent</code> (base<sup class="t-su">exponent</sup>) is returned.</p>
+<p>If a domain error occurs, an implementation-defined value is returned (NaN where supported).</p>
+<p>If a pole error or a range error due to overflow occurs, <code><a href="huge_val" title="c/numeric/math/HUGE VAL">±HUGE_VAL</a></code>, <code>±HUGE_VALF</code>, or <code>±HUGE_VALL</code> is returned.</p>
+<p>If a range error occurs due to underflow, the correct result (after rounding) is returned.</p>
+<h3 id="Error_handling"> Error handling</h3> <p>Errors are reported as specified in <a href="math_errhandling" title="c/numeric/math/math errhandling"><code>math_errhandling</code></a>.</p>
+<p>If <code>base</code> is finite and negative and <code>exponent</code> is finite and non-integer, a domain error occurs and a range error may occur.</p>
+<p>If <code>base</code> is zero and <code>exponent</code> is zero, a domain error may occur.</p>
+<p>If <code>base</code> is zero and <code>exponent</code> is negative, a domain error or a pole error may occur.</p>
+<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559),</p>
+<ul>
+<li> <code>pow(+0, exponent)</code>, where <code>exponent</code> is a negative odd integer, returns <code>+∞</code> and raises <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code> </li>
+<li> <code>pow(-0, exponent)</code>, where <code>exponent</code> is a negative odd integer, returns <code>-∞</code> and raises <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code> </li>
+<li> <code>pow(±0, exponent)</code>, where <code>exponent</code> is negative, finite, and is an even integer or a non-integer, returns +∞ and raises <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code> </li>
+<li> <code>pow(±0, -∞)</code> returns +∞ <span class="t-rev-inl t-until-c23"><span>and may raise <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code></span><span><span class="t-mark-rev t-until-c23">(until C23)</span></span></span> </li>
+<li> <code>pow(+0, exponent)</code>, where <code>exponent</code> is a positive odd integer, returns +0 </li>
+<li> <code>pow(-0, exponent)</code>, where <code>exponent</code> is a positive odd integer, returns -0 </li>
+<li> <code>pow(±0, exponent)</code>, where <code>exponent</code> is positive non-integer or a positive even integer, returns +0 </li>
+<li> <code>pow(-1, ±∞)</code> returns <code>1</code> </li>
+<li> <code>pow(+1, exponent)</code> returns <code>1</code> for any <code>exponent</code>, even when <code>exponent</code> is <code>NaN</code> </li>
+<li> <code>pow(base, ±0)</code> returns <code>1</code> for any <code>base</code>, even when <code>base</code> is <code>NaN</code> </li>
+<li> <code>pow(base, exponent)</code> returns <code>NaN</code> and raises <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> if <code>base</code> is finite and negative and <code>exponent</code> is finite and non-integer. </li>
+<li> <code>pow(base, -∞)</code> returns +∞ for any <code>|base|&lt;1</code> </li>
+<li> <code>pow(base, -∞)</code> returns +0 for any <code>|base|&gt;1</code> </li>
+<li> <code>pow(base, +∞)</code> returns +0 for any <code>|base|&lt;1</code> </li>
+<li> <code>pow(base, +∞)</code> returns +∞ for any <code>|base|&gt;1</code> </li>
+<li> <code>pow(-∞, exponent)</code> returns -0 if <code>exponent</code> is a negative odd integer </li>
+<li> <code>pow(-∞, exponent)</code> returns +0 if <code>exponent</code> is a negative non-integer or negative even integer </li>
+<li> <code>pow(-∞, exponent)</code> returns -∞ if <code>exponent</code> is a positive odd integer </li>
+<li> <code>pow(-∞, exponent)</code> returns +∞ if <code>exponent</code> is a positive non-integer or positive even integer </li>
+<li> <code>pow(+∞, exponent)</code> returns +0 for any negative <code>exponent</code> </li>
+<li> <code>pow(+∞, exponent)</code> returns +∞ for any positive <code>exponent</code> </li>
+<li> except where specified above, if any argument is NaN, NaN is returned </li>
+</ul> <h3 id="Notes"> Notes</h3> <p>Although <code>pow</code> cannot be used to obtain a root of a negative number, <code><a href="cbrt" title="c/numeric/math/cbrt">cbrt</a></code> is provided for the common case where <code>exponent</code> is 1/3.</p>
+<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
+#include &lt;math.h&gt;
+#include &lt;errno.h&gt;
+#include &lt;fenv.h&gt;
+
+#pragma STDC FENV_ACCESS ON
+int main(void)
+{
+ // typical usage
+ printf("pow(2, 10) = %f\n", pow(2,10));
+ printf("pow(2, 0.5) = %f\n", pow(2,0.5));
+ printf("pow(-2, -3) = %f\n", pow(-2,-3));
+ // special values
+ printf("pow(-1, NAN) = %f\n", pow(-1,NAN));
+ printf("pow(+1, NAN) = %f\n", pow(+1,NAN));
+ printf("pow(INFINITY, 2) = %f\n", pow(INFINITY, 2));
+ printf("pow(INFINITY, -1) = %f\n", pow(INFINITY, -1));
+ // error handling
+ errno = 0; feclearexcept(FE_ALL_EXCEPT);
+ printf("pow(-1, 1/3) = %f\n", pow(-1, 1.0/3));
+ if(errno == EDOM) perror(" errno == EDOM");
+ if(fetestexcept(FE_INVALID)) puts(" FE_INVALID raised");
+
+ feclearexcept(FE_ALL_EXCEPT);
+ printf("pow(-0, -3) = %f\n", pow(-0.0, -3));
+ if(fetestexcept(FE_DIVBYZERO)) puts(" FE_DIVBYZERO raised");
+}</pre></div> <p>Possible output:</p>
+<div class="text source-text"><pre data-language="c">pow(2, 10) = 1024.000000
+pow(2, 0.5) = 1.414214
+pow(-2, -3) = -0.125000
+pow(-1, NAN) = nan
+pow(+1, NAN) = 1.000000
+pow(INFINITY, 2) = inf
+pow(INFINITY, -1) = 0.000000
+pow(-1, 1/3) = -nan
+ errno == EDOM: Numerical argument out of domain
+ FE_INVALID raised
+pow(-0, -3) = -inf
+ FE_DIVBYZERO raised</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C23 standard (ISO/IEC 9899:2023): </li>
+<ul>
+<li> 7.12.7.5 The pow functions </li>
+<li> 7.27 Type-generic math &lt;tgmath.h&gt; </li>
+<li> F.10.4.5 The pow functions (p: 524-525) </li>
+</ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul>
+<li> 7.12.7.4 The pow functions (p: 248-249) </li>
+<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </li>
+<li> F.10.4.4 The pow functions (p: 524-525) </li>
+</ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul>
+<li> 7.12.7.4 The pow functions (p: 248-249) </li>
+<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </li>
+<li> F.10.4.4 The pow functions (p: 524-525) </li>
+</ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul>
+<li> 7.12.7.4 The pow functions (p: 229) </li>
+<li> 7.22 Type-generic math &lt;tgmath.h&gt; (p: 335-337) </li>
+<li> F.9.4.4 The pow functions (p: 461) </li>
+</ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 4.5.5.1 The pow function </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="sqrt" title="c/numeric/math/sqrt"> <span class="t-lines"><span>sqrt</span><span>sqrtf</span><span>sqrtl</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes square root (\(\small{\sqrt{x} }\)<span class="t-mrad"><span>√</span><span>x</span></span>) <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="cbrt" title="c/numeric/math/cbrt"> <span class="t-lines"><span>cbrt</span><span>cbrtf</span><span>cbrtl</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes cube root (\(\small{\sqrt[3]{x} }\)<span class="t-mrad"><span>3</span><span>√</span><span>x</span></span>) <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="hypot" title="c/numeric/math/hypot"> <span class="t-lines"><span>hypot</span><span>hypotf</span><span>hypotl</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes square root of the sum of the squares of two given numbers (\(\scriptsize{\sqrt{x^2+y^2} }\)<span class="t-mrad"><span>√</span><span>x<sup class="t-su">2</sup>+y<sup class="t-su">2</sup></span></span>) <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="../complex/cpow" title="c/numeric/complex/cpow"> <span class="t-lines"><span>cpow</span><span>cpowf</span><span>cpowl</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes the complex power function <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/pow" title="cpp/numeric/math/pow">C++ documentation</a></span> for <code>pow</code> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/numeric/math/pow" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/pow</a>
+ </p>
+</div>