My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cmplx.h
Go to the documentation of this file.
1 /*
2  * cmplx.h - complex number class definitions
3  *
4  * Copyright (C) 2003, 2004, 2005, 2006, 2007 Stefan Jahn <stefan@lkcc.org>
5  * Copyright (C) 2006 Gunther Kraut <gn.kraut@t-online.de>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * $Id: cmplx.h 1825 2011-03-11 20:42:14Z ela $
23  *
24  */
25 
26 #ifndef __CMPLX_H__
27 #define __CMPLX_H__
28 
29 #ifdef log2
30 #undef log2
31 #endif
32 
33 /*\brief Complex class
34  Implement a generic complex class
35 */
36 class cmplx
37 {
38  private:
39  nr_double_t r;
40  nr_double_t i;
41 
42  public:
43  cmplx (nr_double_t real, nr_double_t imag = 0.0);
44  cmplx ();
45  cmplx (const cmplx&);
46 
47  // complex manipulations
48  friend nr_double_t arg (const cmplx); // the angle in the plane
49  friend nr_double_t real (const cmplx); // the real part
50  friend nr_double_t imag (const cmplx); // the imaginary part
51  friend cmplx conj (const cmplx); // the complex conjugate
52  friend nr_double_t abs (const cmplx); // the magnitude
53 
54  nr_double_t arg (void); // the angle in the plane
55  nr_double_t real (void); // the real part
56  nr_double_t imag (void); // the imaginary part
57  cmplx conj (void); // the complex conjugate
58  nr_double_t abs (void); // the magnitude
59  nr_double_t norm (void); // the square of the magnitude
60 
61  // operator functions
62  friend cmplx operator + (const cmplx, const cmplx);
63  friend cmplx operator + (const cmplx, const nr_double_t);
64  friend cmplx operator + (const nr_double_t, const cmplx);
65 
66  friend cmplx operator - (const cmplx, const cmplx);
67  friend cmplx operator - (const cmplx, const nr_double_t);
68  friend cmplx operator - (const nr_double_t, const cmplx);
69 
70  friend cmplx operator * (const cmplx, const cmplx);
71  friend cmplx operator * (const cmplx, const nr_double_t);
72  friend cmplx operator * (const nr_double_t, const cmplx);
73 
74  friend cmplx operator / (const cmplx, const cmplx);
75  friend cmplx operator / (const cmplx, const nr_double_t);
76  friend cmplx operator / (const nr_double_t, const cmplx);
77 
78  // assignment operations
79  cmplx& operator = (const cmplx);
80  cmplx& operator = (const nr_double_t);
81 
82  cmplx& operator += (const cmplx);
83  cmplx& operator += (const nr_double_t);
84 
85  cmplx& operator -= (const cmplx);
86  cmplx& operator -= (const nr_double_t);
87 
88  cmplx& operator *= (const cmplx);
89  cmplx& operator *= (const nr_double_t);
90 
91  cmplx& operator /= (const cmplx);
92  cmplx& operator /= (const nr_double_t);
93 
96 
97  // debugging
98  void print (void);
99 };
100 
101 #endif /* __CMPLX_H__ */