diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/numeric%2Fmath%2Fexp.html | |
new repository
Diffstat (limited to 'devdocs/c/numeric%2Fmath%2Fexp.html')
| -rw-r--r-- | devdocs/c/numeric%2Fmath%2Fexp.html | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Fmath%2Fexp.html b/devdocs/c/numeric%2Fmath%2Fexp.html new file mode 100644 index 00000000..0d02bb24 --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fexp.html @@ -0,0 +1,90 @@ + <h1 id="firstHeading" class="firstHeading">exp, expf, expl</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><math.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float expf( float arg );</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 exp( double arg );</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 expl( long double arg );</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><tgmath.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define exp( arg )</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 e (<a href="https://en.wikipedia.org/wiki/E_(mathematical_constant)" class="extiw" title="enwiki:E (mathematical constant)">Euler's number</a>, <span class="nu16">2.7182818</span>...) raised to the given power <code>arg</code>.</div> <div class="t-li1"> +<span class="t-li">4)</span> Type-generic macro: If <code>arg</code> has type <code>long double</code>, <code>expl</code> is called. Otherwise, if <code>arg</code> has integer type or the type <code>double</code>, <code>exp</code> is called. Otherwise, <code>expf</code> is called. If <code>arg</code> is complex or imaginary, then the macro invokes the corresponding complex function (<code><a href="http://en.cppreference.com/w/c/numeric/complex/cexp"><span class="kw769">cexpf</span></a></code>, <code><a href="http://en.cppreference.com/w/c/numeric/complex/cexp"><span class="kw768">cexp</span></a></code>, <code><a href="http://en.cppreference.com/w/c/numeric/complex/cexp"><span class="kw770">cexpl</span></a></code>).</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating point value </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, the base-<i>e</i> exponential of <code>arg</code> (e<sup class="t-su">arg</sup>) is returned.</p> +<p>If a range error occurs due to overflow, <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 the implementation supports IEEE floating-point arithmetic (IEC 60559),</p> +<ul> +<li> If the argument is ±0, 1 is returned </li> +<li> If the argument is -∞, +0 is returned </li> +<li> If the argument is +∞, +∞ is returned </li> +<li> If the argument is NaN, NaN is returned </li> +</ul> <h3 id="Notes"> Notes</h3> <p>For IEEE-compatible type <code>double</code>, overflow is guaranteed if 709.8 < arg, and underflow is guaranteed if arg < -708.4.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <errno.h> +#include <fenv.h> +#include <float.h> +#include <math.h> +#include <stdio.h> +// #pragma STDC FENV_ACCESS ON + +int main(void) +{ + printf("exp(1) = %f\n", exp(1)); + printf("FV of $100, continuously compounded at 3%% for 1 year = %f\n", + 100*exp(0.03)); + // special values + printf("exp(-0) = %f\n", exp(-0.0)); + printf("exp(-Inf) = %f\n", exp(-INFINITY)); + //error handling + errno = 0; feclearexcept(FE_ALL_EXCEPT); + printf("exp(710) = %f\n", exp(710)); + if (errno == ERANGE) + perror(" errno == ERANGE"); + if (fetestexcept(FE_OVERFLOW)) + puts(" FE_OVERFLOW raised"); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">exp(1) = 2.718282 +FV of $100, continuously compounded at 3% for 1 year = 103.045453 +exp(-0) = 1.000000 +exp(-Inf) = 0.000000 +exp(710) = inf + errno == ERANGE: Numerical result out of range + FE_OVERFLOW raised</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C23 standard (ISO/IEC 9899:2023): </li> +<ul> +<li> 7.12.6.1 The exp functions (p: TBD) </li> +<li> 7.25 Type-generic math <tgmath.h> (p: TBD) </li> +<li> F.10.3.1 The exp functions (p: TBD) </li> +</ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul> +<li> 7.12.6.1 The exp functions (p: 175) </li> +<li> 7.25 Type-generic math <tgmath.h> (p: 272-273) </li> +<li> F.10.3.1 The exp functions (p: 379) </li> +</ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.12.6.1 The exp functions (p: 242) </li> +<li> 7.25 Type-generic math <tgmath.h> (p: 373-375) </li> +<li> F.10.3.1 The exp functions (p: 520) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul> +<li> 7.12.6.1 The exp functions (p: 223) </li> +<li> 7.22 Type-generic math <tgmath.h> (p: 335-337) </li> +<li> F.9.3.1 The exp functions (p: 458) </li> +</ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 4.5.4.1 The exp function </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="exp2" title="c/numeric/math/exp2"> <span class="t-lines"><span>exp2</span><span>exp2f</span><span>exp2l</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 <i>2</i> raised to the given power (\({\small 2^x}\)2<sup>x</sup>) <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="expm1" title="c/numeric/math/expm1"> <span class="t-lines"><span>expm1</span><span>expm1f</span><span>expm1l</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 <i>e</i> raised to the given power, minus one (\({\small e^x-1}\)e<sup>x</sup>-1) <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="log" title="c/numeric/math/log"> <span class="t-lines"><span>log</span><span>logf</span><span>logl</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 natural (base-<i>e</i>) logarithm (\({\small \ln{x} }\)ln(x)) <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="../complex/cexp" title="c/numeric/complex/cexp"> <span class="t-lines"><span>cexp</span><span>cexpf</span><span>cexpl</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 base-e exponential <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/exp" title="cpp/numeric/math/exp">C++ documentation</a></span> for <code>exp</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © 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/exp" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/exp</a> + </p> +</div> |
