1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Extension to the c++ complex library type.
34 \*---------------------------------------------------------------------------*/
42 #include "contiguous.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Forward declaration of friend functions and operators
53 inline scalar magSqr(const complex&);
54 inline complex sqr(const complex&);
55 inline scalar mag(const complex&);
56 inline const complex& max(const complex&, const complex&);
57 inline const complex& min(const complex&, const complex&);
58 inline complex limit(const complex&, const complex&);
59 inline const complex& sum(const complex&);
60 inline complex operator+(const complex&, const complex&);
61 inline complex operator-(const complex&);
62 inline complex operator-(const complex&, const complex&);
63 inline complex operator*(const complex&, const complex&);
64 inline complex operator/(const complex&, const complex&);
65 inline complex operator*(const scalar, const complex&);
66 inline complex operator*(const complex&, const scalar);
67 inline complex operator/(const complex&, const scalar);
68 inline complex operator/(const scalar, const complex&);
69 Istream& operator>>(Istream&, complex&);
70 Ostream& operator<<(Ostream&, const complex&);
73 /*---------------------------------------------------------------------------*\
74 Class complex Declaration
75 \*---------------------------------------------------------------------------*/
81 //- Real and imaginary parts of the complex number
87 typedef complex cmptType;
90 // Static data members
92 static const char* const typeName;
94 static const complex zero;
95 static const complex one;
103 //- Construct given real and imaginary parts
104 inline complex(const scalar Re, const scalar Im);
106 //- Construct from Istream
114 inline scalar Re() const;
115 inline scalar Im() const;
124 inline complex conjugate() const;
129 inline const complex& operator=(const complex&);
130 inline void operator+=(const complex&);
131 inline void operator-=(const complex&);
132 inline void operator*=(const complex&);
133 inline void operator/=(const complex&);
135 inline const complex& operator=(const scalar);
136 inline void operator+=(const scalar);
137 inline void operator-=(const scalar);
138 inline void operator*=(const scalar);
139 inline void operator/=(const scalar);
141 inline complex operator!() const;
143 inline bool operator==(const complex&) const;
144 inline bool operator!=(const complex&) const;
149 friend scalar magSqr(const complex& c);
150 friend complex sqr(const complex& c);
151 friend scalar mag(const complex& c);
152 friend const complex& max(const complex&, const complex&);
153 friend const complex& min(const complex&, const complex&);
155 friend complex limit(const complex&, const complex&);
157 friend const complex& sum(const complex&);
162 friend complex operator+(const complex&, const complex&);
163 friend complex operator-(const complex&);
164 friend complex operator-(const complex&, const complex&);
165 friend complex operator*(const complex&, const complex&);
166 friend complex operator/(const complex&, const complex&);
168 friend complex operator*(const scalar, const complex&);
169 friend complex operator*(const complex&, const scalar);
170 friend complex operator/(const complex&, const scalar);
171 friend complex operator/(const scalar, const complex&);
174 // IOstream operators
176 friend Istream& operator>>(Istream&, complex&);
177 friend Ostream& operator<<(Ostream&, const complex&);
182 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
184 //- Return a string representation of a complex
185 word name(const complex&);
188 //- Data associated with complex type are contiguous
190 inline bool contiguous<complex>() {return true;}
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 } // End namespace Foam
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 #include "complexI.H"
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 // ************************************************************************* //