00001 #ifndef Impala_Core_Array_Element_Complex64_h
00002 #define Impala_Core_Array_Element_Complex64_h
00003
00004 #include <iostream>
00005 #include "Util/Math.h"
00006 #include "Basis/NativeTypes.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 namespace Element
00015 {
00016
00017
00020 class Complex64 {
00021 public:
00022
00024 Complex64()
00025 {
00026 }
00027
00029 Complex64(Real64 re, Real64 im)
00030 {
00031 mValues[0] = re;
00032 mValues[1] = im;
00033 }
00034
00036 Complex64(const Complex64& v)
00037 {
00038 mValues[0] = v.mValues[0];
00039 mValues[1] = v.mValues[1];
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00052 Real64
00053 X() const
00054 {
00055 return mValues[0];
00056 }
00057
00059 Real64
00060 Y() const
00061 {
00062 return mValues[1];
00063 }
00064
00065 int
00066 operator==(const Complex64& v) const
00067 {
00068 return (mValues[0] == v.mValues[0]) && (mValues[1] == v.mValues[1]);
00069 }
00070
00071 int
00072 operator!=(const Complex64& v) const
00073 {
00074 return (mValues[0] != v.mValues[0]) || (mValues[1] != v.mValues[1]);
00075 }
00076
00077 int
00078 operator<(const Complex64& v) const
00079 {
00080 return (fabs(mValues[0]) + fabs(mValues[1])) <
00081 (fabs(v.mValues[0]) + fabs(v.mValues[1]));
00082 }
00083
00084 int
00085 operator<=(const Complex64& v) const
00086 {
00087 return (fabs(mValues[0]) + fabs(mValues[1])) <=
00088 (fabs(v.mValues[0]) + fabs(v.mValues[1]));
00089 }
00090
00091 int
00092 operator>(const Complex64& v) const
00093 {
00094 return (fabs(mValues[0]) + fabs(mValues[1])) >
00095 (fabs(v.mValues[0]) + fabs(v.mValues[1]));
00096 }
00097
00098 int
00099 operator>=(const Complex64& v) const
00100 {
00101 return (fabs(mValues[0]) + fabs(mValues[1])) >=
00102 (fabs(v.mValues[0]) + fabs(v.mValues[1]));
00103 }
00104
00105 Complex64&
00106 operator+=(const Complex64& v)
00107 {
00108 mValues[0] += v.mValues[0];
00109 mValues[1] += v.mValues[1];
00110 return *this;
00111 }
00112
00113 private:
00114 Real64 mValues[2];
00115 };
00116
00117 inline std::ostream&
00118 operator<<(std::ostream& os, const Complex64& v)
00119 {
00120 return os << "(" << v.X() << "," << v.Y() << ")";
00121 }
00122
00123 inline Complex64
00124 operator+(const Complex64& v1, const Complex64& v2)
00125 {
00126 return Complex64(v1.X() + v2.X(), v1.Y() + v2.Y());
00127 }
00128
00129 inline Complex64
00130 operator-(const Complex64& v1, const Complex64& v2)
00131 {
00132 return Complex64(v1.X() - v2.X(), v1.Y() - v2.Y());
00133 }
00134
00135 inline Complex64
00136 operator*(const Complex64& v1, const Complex64& v2)
00137 {
00138 double re = v1.X()*v2.X() - v1.Y()*v2.Y();
00139 double im = v1.X()*v2.Y() + v1.Y()*v2.X();
00140
00141 return Complex64(re, im);
00142 }
00143
00144 inline Complex64
00145 operator/(const Complex64& v1, const Complex64& v2)
00146 {
00147 double re = v2.X();
00148 double im = v2.Y();
00149 double sq = re*re+im*im;
00150
00151 double mulre = v1.X()*re + v1.Y()*im;
00152 double mulim = v1.Y()*re - v1.X()*im;
00153
00154 return Complex64(mulre / sq, mulim / sq);
00155 }
00156
00157 }
00158 }
00159 }
00160 }
00161
00162 #endif