summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fcomplex%2Fclog.html
blob: 3cc04584834a4fc26dcf4d5d0bc0b0fd4913de0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    <h1 id="firstHeading" class="firstHeading">clogf, clog, clogl</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;complex.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float complex       clogf( float complex z );</pre>
</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">double complex      clog( double complex z );</pre>
</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long double complex clogl( long double complex z );</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 log( z )</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 complex natural (base-<i>e</i>) logarithm of <code>z</code> with branch cut along the negative real axis.</div> <div class="t-li1">
<span class="t-li">4)</span> Type-generic macro: If <code>z</code> has type <code><span class="kw4">long</span> <span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a></code>, <code>clogl</code> is called. if <code>z</code> has type <code><span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a></code>, <code>clog</code> is called, if <code>z</code> has type <code><span class="kw4">float</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a></code>, <code>clogf</code> is called. If <code>z</code> is real or integer, then the macro invokes the corresponding real function (<code>logf</code>, <code><a href="http://en.cppreference.com/w/c/numeric/math/log"><span class="kw660">log</span></a></code>, <code>logl</code>). If <code>z</code> is imaginary, the corresponding complex number version is called.</div>  <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> z </td> <td> - </td> <td> complex argument </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, the complex natural logarithm of <code>z</code> is returned, in the range of a strip in the interval [−iπ, +iπ] along the imaginary axis and mathematically unbounded along the real axis.</p>
<h3 id="Error_handling_and_special_values"> Error handling and special values</h3> <p>Errors are reported consistent with <a href="../math/math_errhandling" title="c/numeric/math/math errhandling">math_errhandling</a></p>
<p>If the implementation supports IEEE floating-point arithmetic,</p>
<ul>
<li> The function is continuous onto the branch cut taking into account the sign of imaginary part </li>
<li> <code>clog<span class="br0">(</span><a href="http://en.cppreference.com/w/c/numeric/complex/conj"><span class="kw760">conj</span></a><span class="br0">(</span>z<span class="br0">)</span><span class="br0">)</span> <span class="sy1">==</span> <a href="http://en.cppreference.com/w/c/numeric/complex/conj"><span class="kw760">conj</span></a><span class="br0">(</span>clog<span class="br0">(</span>z<span class="br0">)</span><span class="br0">)</span></code> </li>
<li> If <code>z</code> is <code>-0+0i</code>, the result is <code>-∞+πi</code> and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code> is raised </li>
<li> If <code>z</code> is <code>+0+0i</code>, the result is <code>-∞+0i</code> and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code> is raised </li>
<li> If <code>z</code> is <code>x+∞i</code> (for any finite x), the result is <code>+∞+πi/2</code> </li>
<li> If <code>z</code> is <code>x+NaNi</code> (for any finite x), the result is <code>NaN+NaNi</code> and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> may be raised </li>
<li> If <code>z</code> is <code>-∞+yi</code> (for any finite positive y), the result is <code>+∞+πi</code> </li>
<li> If <code>z</code> is <code>+∞+yi</code> (for any finite positive y), the result is <code>+∞+0i</code> </li>
<li> If <code>z</code> is <code>-∞+∞i</code>, the result is <code>+∞+3πi/4</code> </li>
<li> If <code>z</code> is <code>+∞+∞i</code>, the result is <code>+∞+πi/4</code> </li>
<li> If <code>z</code> is <code>±∞+NaNi</code>, the result is <code>+∞+NaNi</code> </li>
<li> If <code>z</code> is <code>NaN+yi</code> (for any finite y), the result is <code>NaN+NaNi</code> and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> may be raised </li>
<li> If <code>z</code> is <code>NaN+∞i</code>, the result is <code>+∞+NaNi</code> </li>
<li> If <code>z</code> is <code>NaN+NaNi</code>, the result is <code>NaN+NaNi</code> </li>
</ul> <h3 id="Notes"> Notes</h3> <p>The natural logarithm of a complex number z with polar coordinate components (r,θ) equals ln r + i(θ+2nπ), with the principal value ln r + iθ</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;complex.h&gt;
 
int main(void)
{
    double complex z = clog(I); // r = 1, θ = pi/2
    printf("2*log(i) = %.1f%+fi\n", creal(2*z), cimag(2*z));
 
    double complex z2 = clog(sqrt(2)/2 + sqrt(2)/2*I); // r = 1, θ = pi/4
    printf("4*log(sqrt(2)/2+sqrt(2)i/2) = %.1f%+fi\n", creal(4*z2), cimag(4*z2));
 
    double complex z3 = clog(-1); // r = 1, θ = pi
    printf("log(-1+0i) = %.1f%+fi\n", creal(z3), cimag(z3));
 
    double complex z4 = clog(conj(-1)); // or clog(CMPLX(-1, -0.0)) in C11
    printf("log(-1-0i) (the other side of the cut) = %.1f%+fi\n", creal(z4), cimag(z4));
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">2*log(i) = 0.0+3.141593i
4*log(sqrt(2)/2+sqrt(2)i/2) = 0.0+3.141593i
log(-1+0i) = 0.0+3.141593i
log(-1-0i) (the other side of the cut) = 0.0-3.141593i</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul>
<li> 7.3.7.2 The clog functions (p: 195) </li>
<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </li>
<li> G.6.3.2 The clog functions (p: 543-544) </li>
<li> G.7 Type-generic math &lt;tgmath.h&gt; (p: 545) </li>
</ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul>
<li> 7.3.7.2 The clog functions (p: 176-177) </li>
<li> 7.22 Type-generic math &lt;tgmath.h&gt; (p: 335-337) </li>
<li> G.6.3.2 The clog functions (p: 478-479) </li>
<li> G.7 Type-generic math &lt;tgmath.h&gt; (p: 480) </li>
</ul>
</ul>            <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="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> <div><a href="../math/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 colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/complex/log" title="cpp/numeric/complex/log">C++ documentation</a></span> for <code>log</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/complex/clog" class="_attribution-link">https://en.cppreference.com/w/c/numeric/complex/clog</a>
  </p>
</div>