summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fcomplex%2Fcproj.html
blob: f74622ea83cf3d106570b519b6571ac46a4b9182 (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
    <h1 id="firstHeading" class="firstHeading">cprojf, cproj, cprojl</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       cprojf( 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      cproj( 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 cprojl( 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 cproj( 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 projection of <code>z</code> on the Riemann sphere.</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><span class="kw4">long</span> <span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/imaginary"><span class="kw745">imaginary</span></a></code>, or <code>long double</code>, <code>cprojl</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><span class="kw4">float</span> <a href="http://en.cppreference.com/w/c/numeric/complex/imaginary"><span class="kw745">imaginary</span></a></code>, or <code>float</code>, <code>cprojf</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><span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/imaginary"><span class="kw745">imaginary</span></a></code>, <code>double</code>, or any integer type, <code>cproj</code> is called.</div> <p>For most <code>z</code>, <code>cproj(z)==z</code>, but all complex infinities, even the numbers where one component is infinite and the other is NaN, become positive real infinity, <code>INFINITY+0.0*I</code> or <code>INFINITY-0.0*I</code>. The sign of the imaginary (zero) component is the sign of <code><a href="http://en.cppreference.com/w/c/numeric/complex/cimag"><span class="kw751">cimag</span></a><span class="br0">(</span>z<span class="br0">)</span></code>.</p>
<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>The projection of <code>z</code> on the Riemann sphere.</p>
<p>This function is fully specified for all possible inputs and is not subject to any errors described in <a href="../math/math_errhandling" title="c/numeric/math/math errhandling">math_errhandling</a></p>
<h3 id="Notes"> Notes</h3> <p>The <code>cproj</code> function helps model the Riemann sphere by mapping all infinities to one (give or take the sign of the imaginary zero), and should be used just before any operation, especially comparisons, that might give spurious results for any of the other infinities.</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;complex.h&gt;
#include &lt;math.h&gt;
 
int main(void)
{
    double complex z1 = cproj(1 + 2*I);
    printf("cproj(1+2i) = %.1f%+.1fi\n", creal(z1),cimag(z1));
 
    double complex z2 = cproj(INFINITY+2.0*I);
    printf("cproj(Inf+2i) = %.1f%+.1fi\n", creal(z2),cimag(z2));
 
    double complex z3 = cproj(INFINITY-2.0*I);
    printf("cproj(Inf-2i) = %.1f%+.1fi\n", creal(z3),cimag(z3));
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">cproj(1+2i) = 1.0+2.0i
cproj(Inf+2i) = inf+0.0i
cproj(Inf-2i) = inf-0.0i</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul>
<li> 7.3.9.5 The cproj functions (p: 198) </li>
<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </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.9.4 The cproj functions (p: 179) </li>
<li> 7.22 Type-generic math &lt;tgmath.h&gt; (p: 335-337) </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 colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/complex/proj" title="cpp/numeric/complex/proj">C++ documentation</a></span> for <code>proj</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/cproj" class="_attribution-link">https://en.cppreference.com/w/c/numeric/complex/cproj</a>
  </p>
</div>