1 /*-*-c++-*-****************************************************************
2  *                     lacomplex.h Helper file for complex numbers
3                        -------------------
4  begin                : 2004-01-14
5  copyright            : (C) 2004 by Christian Stimming
6  email                : stimming@tuhh.de
7 ***************************************************************************/
8 
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2, or (at your option) any later version.
13 
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU Lesser General Public License for more details.
18 
19 // You should have received a copy of the GNU Lesser General
20 // Public License along with this library; see the file COPYING.
21 // If not, write to the Free Software Foundation, 59 Temple Place
22 // - Suite 330, Boston, MA 02111-1307, USA.
23 
24 #ifndef _LACOMPLEX_H
25 #define _LACOMPLEX_H
26 
27 /** @file
28 
29 @brief Helper file for complex numbers
30 
31 This file exists to be a replacement to Lapack++'s inclusion of
32 <complex.h>.
33 
34 @note Complex numbers are a difficult issue. This solution might be
35 non-trivial to understand, but please bear in mind that complex
36 numbers are really a nuisance in the C++ programming language.
37 
38 This file is being used to help the automated conversion from
39 LAPACK++'s legacy type COMPLEX to the current up-to-date type
40 std::complex<double>. More information at the type definitions below.
41 
42 */
43 
44 // Include the version number defines
45 #include <laversion.h>
46 
47 // Include the FORTRAN definitions from LAPACK++
48 #include <f2c.h>
49 
50 
51 // ////////////////////////////////////////////////////////////
52 
53 /** An application must define LA_COMPLEX_SUPPORT if it wants to use
54  * complex numbers here. */
55 #ifdef LA_COMPLEX_SUPPORT
56 
57 /** @brief Complex type that is used in LAPACK++ internally.
58 
59 The complex type inside LAPACK++ should be the FORTRAN type, since
60 LAPACK++ has to pass these values back and forth to the FORTRAN
61 functions. Don't use this data type anywhere outside anymore. */
62 typedef doublecomplex COMPLEX;
63 
64 // As opposed to the FORTRAN "COMPLEX", include now the
65 // std::complex<double> type.
66 #include <complex>
67 // And finally include the la::complex<double> which is a copy of
68 // std::complex<double> with additional type conversions.
69 #include <lacomplex>
70 
71 /** @brief Complex data type that can be used from the application.
72  *
73  * This type is used for passing scalars in and out of LAPACK++. It is
74  * a copy of the \c std::complex<double> and it includes automatic
75  * conversion from and to \c std::complex<double>. Additionally it
76  * includes automatic conversion from and to the internal FORTRAN type
77  * COMPLEX, which is why this class is needed to pass complex values
78  * into Lapack++.
79  *
80  * Again: If you get errors when passing a \c std::complex<double>
81  * into Lapack++, then you first need to convert your \c
82  * std::complex<double> into this \c LaComplex value.
83  */
84 typedef la::complex<double> LaComplex;
85 
86 /** Additional operator to make stream output easier.
87 */
88 inline std::ostream&
89 operator<<(std::ostream& __os, const COMPLEX& __x)
90 {
91     return __os << LaComplex(__x);
92 }
93 
94 /** Equality operator for \ref COMPLEX. (New in lapackpp-2.4.5) */
95 inline bool operator==(const COMPLEX& _a, const COMPLEX& _b)
96 {
97     return _a.r == _b.r && _a.i == _b.i;
98 }
99 /** Inequality operator for \ref COMPLEX. (New in lapackpp-2.4.5) */
100 inline bool operator!=(const COMPLEX& _a, const COMPLEX& _b)
101 {
102     return _a.r != _b.r || _a.i != _b.i;
103 }
104 
105 #endif /* LA_COMPLEX_SUPPORT */
106 
107 // ////////////////////////////////////////////////////////////
108 
109 #endif // _LACOMPLEX_H
110