📄 complex.html
字号:
<HTML><HEAD><TITLE><complex></TITLE></HEAD><BODY><H1><A NAME="<complex>"><CODE><complex></CODE></A></H1><HR><P><B><CODE><A HREF="#abs">abs</A>· <A HREF="#arg">arg</A>· <A HREF="#complex">complex</A>· <A HREF="#complex<double>">complex<double></A>· <A HREF="#complex<float>">complex<float></A>· <A HREF="#complex<long double>">complex<long double></A>· <A HREF="#conj">conj</A>· <A HREF="#cos">cos</A>· <A HREF="#cosh">cosh</A>· <A HREF="#exp">exp</A>· <A HREF="#imag">imag</A>· <A HREF="#log">log</A>· <A HREF="#log10">log10</A>· <A HREF="#norm">norm</A>· <A HREF="#operator!=">operator!=</A>· <A HREF="#operator*">operator*</A>· <A HREF="#operator+">operator+</A>· <A HREF="#operator-">operator-</A>· <A HREF="#operator/">operator/</A>· <A HREF="#operator<<">operator<<</A>· <A HREF="#operator==">operator==</A>· <A HREF="#operator>>">operator>></A>· <A HREF="#polar">polar</A>· <A HREF="#pow">pow</A>· <A HREF="#real">real</A>· <A HREF="#sin">sin</A>· <A HREF="#sinh">sinh</A>· <A HREF="#sqrt">sqrt</A>· <A HREF="#tan">tan</A>· <A HREF="#tanh">tanh</A>· <A HREF="#__STD_COMPLEX">__STD_COMPLEX</A></CODE></B></P><HR><P>Include the standard header <B><CODE><complex></CODE></B>to define template class <CODE>complex</CODE> and a host ofsupporting template functions.Unless otherwise specified,functions that can return multiple values return an imaginarypart in the half-open interval <CODE>(-pi, pi]</CODE>.</P><PRE>namespace std {#define <B><A HREF="#__STD_COMPLEX">__STD_COMPLEX</A></B> // TEMPLATE CLASSEStemplate<class Ty> class <B><A HREF="#complex">complex</A></B>;template<> class <B><A HREF="#complex<float>">complex<float></A></B>;template<> class <B><A HREF="#complex<double>">complex<double></A></B>;template<> class <B><A HREF="#complex<long double>">complex<long double></A></B>; // TEMPLATE FUNCTIONStemplate<class Ty> complex<Ty> <B><A HREF="#operator+">operator+</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator+">operator+</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> complex<Ty> <B><A HREF="#operator+">operator+</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator-">operator-</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator-">operator-</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> complex<Ty> <B><A HREF="#operator-">operator-</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator*">operator*</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator*">operator*</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> complex<Ty> <B><A HREF="#operator*">operator*</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator/">operator/</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator/">operator/</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> complex<Ty> <B><A HREF="#operator/">operator/</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#operator+">operator+</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#operator-">operator-</A></B>(const complex<Ty>& left);template<class Ty> bool <B><A HREF="#operator==">operator==</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> bool <B><A HREF="#operator==">operator==</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> bool <B><A HREF="#operator==">operator==</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty> bool <B><A HREF="#operator!=">operator!=</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> bool <B><A HREF="#operator!=">operator!=</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> bool <B><A HREF="#operator!=">operator!=</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty, class Elem, class Tr> basic_istream<Elem, Tr>& <B><A HREF="#operator>>">operator>></A></B>(basic_istream<Elem, Tr>& istr, complex<Ty>& right);template<class Ty, class Elem, class Tr> basic_ostream<Elem, Tr>& <B><A HREF="#operator<<">operator<<</A></B>(basic_ostream<Elem, Tr>& ostr, const complex<Ty>& right);template<class Ty> Ty <B><A HREF="#real">real</A></B>(const complex<Ty>& left);template<class Ty> Ty <B><A HREF="#imag">imag</A></B>(const complex<Ty>& left);template<class Ty> Ty <B><A HREF="#abs">abs</A></B>(const complex<Ty>& left);template<class Ty> Ty <B><A HREF="#arg">arg</A></B>(const complex<Ty>& left);template<class Ty> Ty <B><A HREF="#norm">norm</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#conj">conj</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#polar">polar</A></B>(const Ty& rho, const Ty& theta = 0);template<class Ty> complex<Ty> <B><A HREF="#cos">cos</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#cosh">cosh</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#exp">exp</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#log">log</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#log10">log10</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#pow">pow</A></B>(const complex<Ty>& left, int right);template<class Ty> complex<Ty> <B><A HREF="#pow">pow</A></B>(const complex<Ty>& left, const Ty& right);template<class Ty> complex<Ty> <B><A HREF="#pow">pow</A></B>(const complex<Ty>& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#pow">pow</A></B>(const Ty& left, const complex<Ty>& right);template<class Ty> complex<Ty> <B><A HREF="#sin">sin</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#sinh">sinh</A></B>(const complex<Ty>& left);template<class Ty> complex<Ty> <B><A HREF="#sqrt">sqrt</A></B>(const complex<Ty>& left); };</PRE><H2><A NAME="abs"><CODE>abs</CODE></A></H2><PRE>template<class Ty> Ty <B>abs</B>(const complex<Ty>& left);</PRE><P>The function returns the magnitude of <CODE>left</CODE>.</P><H2><A NAME="arg"><CODE>arg</CODE></A></H2><PRE>template<class Ty> Ty <B>arg</B>(const complex<Ty>& left);</PRE><P>The function returns the phase angle of <CODE>left</CODE>.</P><H2><A NAME="complex"><CODE>complex</CODE></A></H2><PRE>template<class Ty> class <B>complex</B> {public: typedef Ty <B><A HREF="#complex::value_type">value_type</A></B>; Ty <B><A HREF="#complex::real">real</A></B>() const; Ty <B><A HREF="#complex::imag">imag</A></B>() const; <B><A HREF="#complex::complex">complex</A></B>(const Ty& realval = 0, const Ty& imagval = 0); template<class Other> <B><A HREF="#complex::complex">complex</A></B>(const complex<Other>& right); template<class Other> complex& <B><A HREF="#complex::operator=">operator=</A></B>(const complex<Other>& right); template<class Other> complex& <B><A HREF="#complex::operator+=">operator+=</A></B>(const complex<Other>& right); template<class Other> complex& <B><A HREF="#complex::operator-=">operator-=</A></B>(const complex<Other>& right); template<class Other> complex& <B><A HREF="#complex::operator*=">operator*=</A></B>(const complex<Other>& right); template<class Other> complex& <B><A HREF="#complex::operator/=">operator/=</A></B>(const complex<Other>& right); complex& <B><A HREF="#complex::operator=">operator=</A></B>(const Ty& right); complex& <B><A HREF="#complex::operator+=">operator+=</A></B>(const Ty& right); complex& <B><A HREF="#complex::operator-=">operator-=</A></B>(const Ty& right); complex& <B><A HREF="#complex::operator*=">operator*=</A></B>(const Ty& right); complex& <B><A HREF="#complex::operator/=">operator/=</A></B>(const Ty& right); };</PRE><P>The template class describes an object that stores two objectsof type <B><CODE>Ty</CODE></B>, one that represents the real partof a complex number and one that represents the imaginary part.An object of class <CODE>Ty</CODE>:</P><UL><LI>has a public default constructor, destructor,copy constructor, and assignment operator -- withconventional behavior</LI><LI>can be assigned integer or floating-point values, ortype cast to such values -- withconventional behavior</LI><LI>defines the arithmetic operators and math functions, as needed,that are defined for the floating-pointtypes -- with conventional behavior</LI></UL><P>In particular, no subtle differences may exist between copy constructionand default construction followed by assignment. And none of the operationson objects of class <CODE>Ty</CODE> may throw exceptions.</P><P>Explicit specializations of template class <CODE>complex</CODE>exist for the three floating-point types. In this<A HREF="index.html#implementation">implementation</A>, a value of any othertype <CODE>Ty</CODE> is type cast to <I>double</I> for actual calculations,with the <I>double</I> result assigned back to the stored objectof type <CODE>Ty</CODE>.</P><H3><A NAME="complex::complex"><CODE>complex::complex</CODE></A></H3><PRE><B>complex</B>(const Ty& realval = 0, const Ty& imagval = 0);template<class Other> <B>complex</B>(const complex<Other>& right);</PRE><P>The first constructor initializes the stored real part to<CODE>realval</CODE> and the stored imaginary part to <CODE>imagval</CODE>.The second constructor initializes the stored real part to<CODE>right.real()</CODE> and the stored imaginary part to<CODE>right.imag()</CODE>.</P><P>In this<A HREF="index.html#implementation">implementation</A>, if atranslator does not support member template functions, the template:</P><PRE>template<class Other> <B>complex</B>(const complex<Other>& right);</PRE><P>is replaced by:</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -