📄 com_8038.htm
字号:
template<class T> complex<T>
<B>operator-</B> (T lhs, const complex<T>& rhs);</PRE>
<UL><P>Returns the difference of <SAMP>lhs</SAMP> and <SAMP>rhs</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>operator*</B> (const complex<T>& lhs,const complex<T>& rhs);
template<class T> complex<T>
<B>operator*</B> (const complex<T>& lhs, T rhs);
template<class T> complex<T>
<B>operator*</B> (T lhs, const complex<T>& rhs);</PRE>
<UL><P>Returns the product of <SAMP>lhs</SAMP> and <SAMP>rhs</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>operator/</B> (const complex<T>& lhs,const complex<T>& rhs);
template<class T> complex<T>
<B>operator/</B> (const complex<T>& lhs, T rhs);
template<class T> complex<T>
<B>operator/</B> (T lhs, const complex<T>& rhs);</PRE>
<UL><P>Returns the quotient of <SAMP>lhs</SAMP> divided by <SAMP>rhs</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>operator+</B> (const complex<T>& rhs);</PRE>
<UL><P>Returns <SAMP>rhs</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>operator-</B> (const complex<T>& lhs);</PRE>
<UL><P>Returns <SAMP>complex<T>(-lhs.real(), -lhs.imag())</SAMP>.</P>
</UL>
<PRE>template<class T> bool
<B>operator==</B> (const complex<T>& x, const complex<T>& y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if the real and imaginary parts of <SAMP>x</SAMP> and <SAMP>y</SAMP> are equal.</P>
</UL>
<PRE>template<class T> bool
<B>operator==</B> (const complex<T>& x, T y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if <SAMP>y</SAMP> is equal to the real part of <SAMP>x</SAMP> and the imaginary part of <SAMP>x</SAMP> is equal to 0.</P>
</UL>
<PRE>template<class T> bool
<B>operator==</B> (T x, const complex<T>& y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if <SAMP>x</SAMP> is equal to the real part of <SAMP>y</SAMP> and the imaginary part of <SAMP>y</SAMP> is equal to 0.</P>
</UL>
<PRE>template<class T> bool
<B>operator!=</B> (const complex<T>& x, const complex<T>& y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if either the real or the imaginary part of <SAMP>x</SAMP> and <SAMP>y</SAMP> are not equal.</P>
</UL>
<PRE>template<class T> bool
<B>operator!=</B> (const complex<T>& x, T y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if <SAMP>y</SAMP> is not equal to the real part of <SAMP>x</SAMP> or the imaginary part of <SAMP>x</SAMP> is not equal to 0.</P>
</UL>
<PRE>template<class T> bool
<B>operator!=</B> (T x, const complex<T>& y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if <SAMP>x</SAMP> is not equal to the real part of <SAMP>y</SAMP> or the imaginary part of <SAMP>y</SAMP> is not equal to 0.</P>
</UL>
<PRE>template <class X> istream&
<B>operator>></B> (istream& is, complex<X>& x);</PRE>
<UL><P>Reads a complex number <SAMP>x</SAMP> into the input stream <SAMP>is</SAMP>. <SAMP>x</SAMP> may be of the form <SAMP>u</SAMP>, <SAMP>(u)</SAMP>, or <SAMP>(u,v)</SAMP> where <SAMP>u</SAMP> is the real part and <SAMP>v</SAMP> is the imaginary part. If bad input is encountered, the <SAMP>ios::badbit flag</SAMP> is set.</P>
</UL>
<PRE>template <class X> ostream&
<B>operator<<</B> (ostream& os, const complex<X>& x);</PRE>
<UL><P>Returns <SAMP>os << "(" << x.real() << "," << x.imag() << ")"</SAMP>.</P>
</UL>
<A NAME="Non-member Functions"><H3>Non-member Functions</H3></A>
<PRE>template<class T> T
<B>abs</B>(const complex<T>& c);</PRE>
<UL><P>Returns the absolute value or magnitude of <SAMP>c</SAMP> (the square root of the norm).</P>
</UL>
<PRE>template<class T> complex<T>
<B>acos</B> (const complex<T>& c);</PRE>
<UL><P>Returns the arccosine of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> T
<B>arg</B> (const complex<T>& c);</PRE>
<UL><P>Returns the phase angle of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>asin</B> (const complex<T>& c);</PRE>
<UL><P>Returns the arcsine of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>atan</B> (const complex<T>& c);</PRE>
<UL><P>Returns the arctangent of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>atan2</B> (T a, const complex<T>& b);</PRE>
<UL><P>Returns the arctangent of <SAMP>a/b</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>atan2</B> (const complex<T>& a, T b);</PRE>
<UL><P>Returns the arctangent of <SAMP>a/b</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>atan2</B> (const complex<T>& a, const complex<T>& b);</PRE>
<UL><P>Returns the arctangent of <SAMP>a/b</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>conj</B> (const complex<T>& c);</PRE>
<UL><P>Returns the conjugate of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>cos</B> (const complex<T>& c);</PRE>
<UL><P>Returns the cosine of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>cosh</B> (const complex<T>& c);</PRE>
<UL><P>Returns the hyperbolic cosine of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>exp</B> (const complex<T>& x);</PRE>
<UL><P>Returns <SAMP>e</SAMP> raised to the <SAMP>x</SAMP> power.</P>
</UL>
<PRE>template<class T> T
<B>imag</B> (const complex<T>& c) const;</PRE>
<UL><P>Returns the imaginary part of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>log</B> (const complex<T>& x);</PRE>
<UL><P>Returns the natural logarithm of <SAMP>x</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>log10</B> (const complex<T>& x);</PRE>
<UL><P>Returns the logarithm base 10 of <SAMP>x</SAMP>.</P>
</UL>
<PRE>template<class T> T
<B>norm</B> (const complex<T>& c);</PRE>
<UL><P>Returns the squared magnitude of <SAMP>c</SAMP>. (The sum of the squares of the real and imaginary parts.)</P>
</UL>
<PRE>template<class T> complex<T>
<B>polar</B> (const T& m, const T& a);</PRE>
<UL><P>Returns the complex value of a complex number whose magnitude is <SAMP>m</SAMP> and phase angle is <SAMP>a</SAMP>, measured in radians.</P>
</UL>
<PRE>template<class T> complex<T>
<B>pow</B> (const complex<T>& x, int y);
template<class T> complex<T>
<B>pow</B> (const complex<T>& x, T y);
template<class T> complex<T>
<B>pow</B> (const complex<T>& x, const complex<T>& y);
template<class T> complex<T>
<B>pow</B> (T x, const complex<T>& y);</PRE>
<UL><P>Returns <SAMP>x</SAMP> raised to the <SAMP>y</SAMP> power.</P>
</UL>
<PRE>template<class T> T
<B>real</B> (const complex<T>& c);</PRE>
<UL><P>Returns the real part of <B>c</B>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>sin</B> (const complex<T>& c);</PRE>
<UL><P>Returns the sine of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>sinh</B> (const complex<T>& c);</PRE>
<UL><P>Returns the hyperbolic sine of <SAMP>c</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>sqrt</B> (const complex<T>& x);</PRE>
<UL><P>Returns the square root of <SAMP>x</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>tan</B> (const complex<T>& x);</PRE>
<UL><P>Returns the tangent of <SAMP>x</SAMP>.</P>
</UL>
<PRE>template<class T> complex<T>
<B>tanh</B> (const complex<T>& x);</PRE>
<UL><P>Returns the hyperbolic tangent of <SAMP>x</SAMP>.</P>
</UL>
<A NAME="Example"><H3>Example</H3></A>
<PRE>//
// complex.cpp
//
#include <complex>
#include <iostream.h>
int main()
{
complex<double> a(1.2, 3.4);
complex<double> b(-9.8, -7.6);
a += b;
a /= sin(b) * cos(a);
b *= log(a) + pow(b, a);
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
Output :
a = (1.42804e-06,-0.0002873), b = (58.2199,69.7354)</PRE>
<A NAME="Warnings"><H3>Warnings</H3></A>
<P>On compilers that don't support member function templates, the arithmetic operators will not work on any arbitrary type. (They will work only on float, double and long doubles.) You also will only be able to perform binary arithmetic on types that are the same. </P>
<P>Compilers that don't support non-converting constructors will permit unsafe downcasts (i.e., long double to double, double to float, long double to float).</P>
<HR>
<A HREF="com_1776.htm"><IMG SRC="images/prev.gif"></A> <A HREF="ref.htm#contents"><IMG SRC="images/toc.gif"></A> <A HREF="Con_2487.htm"><IMG SRC="images/next.gif"></A></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -