📄 cx.htm
字号:
<tr> <td width="26%">imag() const</td> <td width="26%">imaginary part</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">imag()</td> <td width="26%">ref. to imaginary part</td> <td width="12%">Real&</td> <td width="12%">Real&</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">imag_as_imag() const</td> <td width="26%">imaginary part as Imag</td> <td width="12%">Imag</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%">Imag</td> </tr> <tr> <td width="26%">conj() const</td> <td width="26%">conjugate</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%">Polar</td> </tr> <tr> <td width="26%">cabs() const </td> <td width="26%">absolute value</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">cabs()</td> <td width="26%">ref. to absolute value</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%">Real&</td> </tr> <tr> <td width="26%">arg() const</td> <td width="26%">argument</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">sum_square() const</td> <td width="26%">square of cabs</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">operator<TT>+</TT>() const</td> <td width="26%"><TT>+</TT> prefix op.</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%">_I_</td> <td width="12%">Polar</td> </tr> <tr> <td width="26%">operator<TT>-</TT>() const</td> <td width="26%"><TT>-</TT> prefix op.</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%">Imag</td> <td width="12%">Polar</td> </tr> <tr> <td width="26%">theta() const</td> <td width="26%">theta</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">theta()</td> <td width="26%">ref. to theta</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%">Real&</td> </tr> <tr> <td width="26%">quadrant() const</td> <td width="26%">quadrant</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%">Quadrant</td> </tr> <tr> <td width="26%">quadrant()</td> <td width="26%">ref. to quadrant</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%">Quadrant&</td> </tr> <tr> <td width="26%">AssertIsValid() const</td> <td width="26%">check Polar valid</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%">void</td> </tr></table><p>For example:</p><pre> CX z = 3.0 + 4.0 * _I_; cout << z.real() << ", " << z.imag() << endl;</pre><p>outputs 3.0, 4.0 .</p><p>The declaration of <i>z</i> could have been replaced with any of thefollowing:</p><pre> CX z(3.0, 4.0); CX z; z.real() = 3.0; z.imag() = 4.0; CX z = 3.0 + Imag(4.0); Polar p(5.0, atan(4.0 / 3.0)); CX z = p;</pre><p>Note that there are two versions of <i>z.real()</i> and <i>z.imag()</i> for <i>CX</i>variable, <i>z</i>. The non-<i>const</i> version is used when <i>z</i> hasn'tbeen declared as <i>const</i>. This version can be used on the left-hand side ofan = sign. The same applies for <i>p.cabs()</i>, <i>p.theta()</i> and <i>p.quadrant()</i>for <i>Polar</i> variable <i>p</i>.</p><p>It might seem more natural for <i>z.imag()</i> to return a variable of type <i>Imag</i>rather than <i>Real</i>. However, this would be unusual for those used to thestandard library or Fortran. I include another function <i>z.imag_as_imag()</i>which does return the imaginary part as type <i>Imag</i>. Nevertheless, there isa potential source of error, here, if <i>z.imag()</i> is used when <i>z.imag_as_imag()</i>was intended.</p><p><i>sum_square()</i> is the <i>norm</i> function in the standard. It isn't a norm in the mathematical sense so you wouldn't call it <i>norm</i> would you?</p><p><i>AssertIsValid</i> checks that a Polar variable is valid. An exception isthrown if the value is invalid; for example the absolute value of the membervariable <i>Theta</i> is greater than <i>pi</i>/4. This should not be possible unless aPolar object is uninitialised or invalid values have been entered with the <i>cabs</i>, <i>theta</i> or <i>quadrant</i>functions.</p><h2><a name="Global"></a>Global functions</h2><table border="1" cellspacing="0" width="100%" cellpadding="2"> <tr> <td width="26%"><b>Function</b></td> <td width="26%"><b>Description</b></td> <td width="48%" colspan="4" align="center"> <b>Return types with this class</b></td> </tr> <tr> <td width="26%"> </td> <td width="26%"> </td> <td width="12%"><b>CX</b></td> <td width="12%"><b>Imag</b></td> <td width="12%"><b>_I_</b></td> <td width="12%"><b>Polar</b></td> </tr> <tr> <td width="26%">real(.)</td> <td width="26%">real part</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">imag(.)</td> <td width="26%">imaginary part</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">imag_as_imag(.)</td> <td width="26%">imaginary part as Imag</td> <td width="12%">Imag</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%">Imag</td> </tr> <tr> <td width="26%">conj(.)</td> <td width="26%">conjugate</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%">Polar</td> </tr> <tr> <td width="26%">cabs(.)</td> <td width="26%">absolute value</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">fabs(.)</td> <td width="26%">absolute value</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">norm1(.) </td> <td width="26%">fabs(real) + fabs(imag)</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">arg(.) </td> <td width="26%">argument</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">exp(.)</td> <td width="26%">exponential</td> <td width="12%">CX</td> <td width="12%">CX</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">log(.)</td> <td width="26%">natural log</td> <td width="12%">CX</td> <td width="12%">CX</td> <td width="12%"> </td> <td width="12%">CX</td> </tr> <tr> <td width="26%">polar_exp(.)</td> <td width="26%">exponential</td> <td width="12%">Polar</td> <td width="12%">Polar</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">sqrt(.)</td> <td width="26%">square root</td> <td width="12%">CX</td> <td width="12%">CX</td> <td width="12%"> </td> <td width="12%">Polar</td> </tr> <tr> <td width="26%">square(.)</td> <td width="26%">square</td> <td width="12%">CX</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Polar</td> </tr> <tr> <td width="26%">sum_square(.)</td> <td width="26%">square of cabs</td> <td width="12%">Real</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%">Real</td> </tr> <tr> <td width="26%">sin(.)</td> <td width="26%">sin trig. function</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">cos(.)</td> <td width="26%">cos trig. function</td> <td width="12%">CX</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">tan(.)</td> <td width="26%">tan trig. function</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">sinh(.)</td> <td width="26%">sinh hyperbolic fn.</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">cosh(.)</td> <td width="26%">cosh hyperbolic fn.</td> <td width="12%">CX</td> <td width="12%">Real</td> <td width="12%"> </td> <td width="12%"> </td> </tr> <tr> <td width="26%">tanh(.)</td> <td width="26%">tanh hyperbolic fn.</td> <td width="12%">CX</td> <td width="12%">Imag</td> <td width="12%"> </td> <td width="12%"> </td> </tr></table><p>For example:</p><pre> CX z = 3.0 + 4.0 * _I_; cout << real(z) << ", " << imag(z) << endl;</pre><p>outputs 3.0, 4.0 .</p><p>Only the <i>const</i> versions of <i>real(z)</i> and <i>imag(z)</i> areprovided. The comments about the member functions <i>.imag()</i> and <i>.imag_as_imag()</i>also apply here. Note the differences between <i>imag(z)</i>, <i>imag_as_imag(z)</i>and <i>Imag(z)</i>.</p><pre> CX z = 3.0 + 4.0 * _I_; Real a = imag(z); // returns a = 4 Imag b = imag_as_imag(z); // returns b = 4<i>i</i> Imag c = Imag(z); // error, can't convert CX to Imag</pre><p>It is important not to confuse <i>Imag</i> and <i>imag</i> or <i>Real</i> and<i>real</i>.</p><p>The functions <i>fabs</i> and <i>cabs</i> are alternative names for the samefunction.</p><p>The function <i>norm1</i> returns the sum of the absolute values of the realand imaginary parts. This is faster than <i>cabs</i> and may be sufficient fordeciding, for example, whether the absolute value of a complex number is less than some bound.</p><p> The function <i>polar_exp</i> takes the <i>exp</i> of a complex number andreturns the result in polar coordinates.</p><h2><a name="Conversions"></a>Conversions</h2><table border="1" cellspacing="0" width="100%" cellpadding="2"> <tr> <td width="20%"><TT>=</TT>, conversions</td> <td width="80%" colspan="5" align="center"> <i>To</i></td> </tr> <tr> <td width="20%"><i>From</i></td> <td width="16%"><b>CX</b></td> <td width="16%"><b>Real</b></td> <td width="16%"><b>Imag</b></td> <td width="16%"><b>_I_</b></td> <td width="16%"><b>Polar</b></td> </tr> <tr> <td width="20%"><b>CX</b></td> <td width="16%">Yes</td> <td width="16%"> </td> <td width="16%"> </td> <td width="16%"> </td> <td width="16%">Yes</td> </tr> <tr> <td width="20%"><b>Real</b></td> <td width="16%">Yes</td> <td width="16%">(Yes)</td> <td width="16%"> </td> <td width="16%"> </td> <td width="16%">Yes</td> </tr> <tr> <td width="20%"><b>Imag</b></td> <td width="16%">Yes</td> <td width="16%"> </td> <td width="16%">Yes</td> <td width="16%"> </td> <td width="16%">Yes</td> </tr> <tr> <td width="20%"><b>_I_</b></td> <td width="16%">Yes</td> <td width="16%"> </td> <td width="16%">Yes</td> <td width="16%"> </td> <td width="16%">Yes</td> </tr> <tr> <td width="20%"><b>Polar</b></td> <td width="16%">Yes</td> <td width="16%"> </td> <td width="16%"> </td> <td width="16%"> </td> <td width="16%">Yes</td> </tr></table><p>The only conversions allowed are ones that do not lose information (apartfrom round-off error). For example, you cannot convert <i>Polar</i> to <i>Imag</i>.</p><p>I return void from the = operation so you can't do <i>a</i> = <i>b</i> = <i>c</i>;.</p><h2><a name="Binary"></a>Binary functions</h2><h3><a name="Additive"></a>Additive</h3><table border="1" cellspacing="0" width="100%" cellpadding="2"> <tr> <td width="20%"><TT>+</TT>, <TT>-</TT></td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -