1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Extension to the c++ complex library type.
35 \*---------------------------------------------------------------------------*/
43 #include "contiguous.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // Forward declaration of friend functions and operators
54 inline scalar magSqr(const complex&);
55 inline complex sqr(const complex&);
56 inline scalar mag(const complex&);
57 inline const complex& max(const complex&, const complex&);
58 inline const complex& min(const complex&, const complex&);
59 inline complex limit(const complex&, const complex&);
60 inline const complex& sum(const complex&);
61 inline complex operator+(const complex&, const complex&);
62 inline complex operator-(const complex&);
63 inline complex operator-(const complex&, const complex&);
64 inline complex operator*(const complex&, const complex&);
65 inline complex operator/(const complex&, const complex&);
66 inline complex operator*(const scalar, const complex&);
67 inline complex operator*(const complex&, const scalar);
68 inline complex operator/(const complex&, const scalar);
69 inline complex operator/(const scalar, const complex&);
70 Istream& operator>>(Istream&, complex&);
71 Ostream& operator<<(Ostream&, const complex&);
74 /*---------------------------------------------------------------------------*\
75 Class complex Declaration
76 \*---------------------------------------------------------------------------*/
82 //- Real and imaginary parts of the complex number
88 typedef complex cmptType;
91 // Static data members
93 static const char* const typeName;
95 static const complex zero;
96 static const complex one;
104 //- Construct given real and imaginary parts
105 inline complex(const scalar Re, const scalar Im);
107 //- Construct from Istream
115 inline scalar Re() const;
116 inline scalar Im() const;
125 inline complex conjugate() const;
130 inline const complex& operator=(const complex&);
131 inline void operator+=(const complex&);
132 inline void operator-=(const complex&);
133 inline void operator*=(const complex&);
134 inline void operator/=(const complex&);
136 inline const complex& operator=(const scalar);
137 inline void operator+=(const scalar);
138 inline void operator-=(const scalar);
139 inline void operator*=(const scalar);
140 inline void operator/=(const scalar);
142 inline complex operator!() const;
144 inline bool operator==(const complex&) const;
145 inline bool operator!=(const complex&) const;
150 friend scalar magSqr(const complex& c);
151 friend complex sqr(const complex& c);
152 friend scalar mag(const complex& c);
153 friend const complex& max(const complex&, const complex&);
154 friend const complex& min(const complex&, const complex&);
156 friend complex limit(const complex&, const complex&);
158 friend const complex& sum(const complex&);
163 friend complex operator+(const complex&, const complex&);
164 friend complex operator-(const complex&);
165 friend complex operator-(const complex&, const complex&);
166 friend complex operator*(const complex&, const complex&);
167 friend complex operator/(const complex&, const complex&);
169 friend complex operator*(const scalar, const complex&);
170 friend complex operator*(const complex&, const scalar);
171 friend complex operator/(const complex&, const scalar);
172 friend complex operator/(const scalar, const complex&);
175 // IOstream operators
177 friend Istream& operator>>(Istream&, complex&);
178 friend Ostream& operator<<(Ostream&, const complex&);
183 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
185 //- Return a string representation of a complex
186 word name(const complex&);
189 //- Data associated with complex type are contiguous
191 inline bool contiguous<complex>() {return true;}
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 } // End namespace Foam
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 #include "complexI.H"
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 // ************************************************************************* //