Borderbasix

RealOf.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 * This file is part of the source code of BORDERBASIX software. *
3 * (C) B. Mourrain, INRIA *
4 **********************************************************************
5 History:
6 $Id: RealOf.hpp,v 1.1.1.1 2006/10/06 08:01:40 trebuche Exp $
7 **********************************************************************/
8 /*
9  RealOf.hpp
10  definitions of two functions :
11  Root_Unity : returns a n- root of unity
12  pow : power function to a complex
13 
14  complex<Scl<MP_FLOAT> > specialization
15 
16 */
17 
18 #ifndef INCLUDED_COMPLEXH
19 #define INCLUDED_COMPLEXH
20 #include <complex>
21 #define COMPLEX complex<double>
22 //----------------------------------------------------------------------------
23 struct Real;
24 //----------------------------------------------------------------------------
25 #ifdef _SCL_H_
26 //----------------------------------------------------------------------------
27 template<class T> struct Scl;
28 //----------------------------------------------------------------------------
29 #endif //
30 
31 
32 
34 
50 template <class T> struct RealOf {
52 };
53 
55 template <> struct RealOf<double> {
56  typedef double TYPE;
57  static inline void assign(double & a, const complex<double> & b)
58  { a = b.real() ;};
59  static inline double absolute(const double & a)
60  { return abs(a); }
61 };
62 
64 template <> struct RealOf<int> {
65  typedef int TYPE;
66  static inline void assign(complex<int> & a, const complex<int> & b)
67  { a = b.real() ;};
68  static inline int absolute(const complex<int> & a);
69  // { return (int) abs(a); }
70 };
71 
73 template <class T> struct RealOf<complex<T> > {
74  typedef T TYPE;
75  static inline void assign(complex<T> & a, const complex<T> & b)
76  { a = b ;};
77  static inline double absolute(const complex<T> & a);
78  // { return abs(a); }
79 };
80 
81 #if 0//def _SCL_MPF_H_
82 //extern "C++"
83 typedef __mpf_struct MP_FLOAT; //struct MP_FLOAT;
84 template<class T> struct Scl;
85 
86 
87 //extern struct Scl<MP_FLOAT>;
88 /*
89 template <> struct RealOf<complex<Scl<MP_FLOAT> > > {
90  typedef typename Scl<MP_FLOAT> TYPE;
91  static inline void assign(complex<Scl<MP_FLOAT> > & a,
92  const complex<Scl<MP_FLOAT> > & b) {a = b ;};
93  static inline Scl<MP_FLOAT> absolute(const complex<Scl<MP_FLOAT> > & a)
94  {return sqrt(pow(a.real(),2)+pow(a.imag(),2)); }
95  };
96 
97 template <> struct RealOf<Scl<MP_FLOAT> > {
98  typedef Scl<MP_FLOAT> TYPE;
99  static inline void assign(Scl<MP_FLOAT> & a, const complex<Scl<MP_FLOAT> > & b) {a = b.real() ;};
100  static inline Scl<MP_FLOAT> absolute(const Scl<MP_FLOAT> & a) { return abs(a); }
101  };
102 */
103 
104 //----------------------------------------------------------------------------
105 //template<class T> struct Scl;
106 //struct MP_FLOAT;
107 
108 /*
109  complex<Scl<MP_FLOAT> > specialization
110 */
111 
112 template <class T> inline void __div_1(T& a, T& b, const T& c, const T& d)
113 {
114  T r(d);r/=c;
115  T s(d); s*=r; s+=c;
116  T x(b); x*=r; x+=a;x/=s;
117  a*=r;
118  b -= a; b /= s;
119  a = x;
120 }
121 
122 template <>
123 inline complex<Scl<MP_FLOAT> >& complex<Scl<MP_FLOAT> >::operator /=(const complex<Scl<MP_FLOAT> > &y) {
124  __div_1(re,im , y.real(), y.imag());
125  return *this;
126 }
127 
128 template<> inline complex<Scl<MP_FLOAT> > pow(const complex<Scl<MP_FLOAT> >& z, int k) {
129  double mod = sqrt(norm(complex<double>(ToDouble(z.real()),ToDouble(z.imag()))));
130  if (k == 0)
131  return complex<Scl<MP_FLOAT> > (Scl<MP_FLOAT>(1), Scl<MP_FLOAT>(0));
132  else
133  if (k == -1)
134  return complex<Scl<MP_FLOAT> >(z.real(),Scl<MP_FLOAT>(-1.0*ToDouble(z.imag())/mod));
135  else {
136  double argument = k * arg(complex<double>(ToDouble(z.real()),ToDouble(z.imag())));
137  mod = pow(mod,k);
138  return complex<Scl<MP_FLOAT> > (mod*cos(argument), mod*sin(argument));
139  }
140 }
141 
142 inline complex<Scl<MP_FLOAT> >
143 operator / (const complex<Scl<MP_FLOAT> >& x, double y) {
144  Scl<MP_FLOAT> d(y);
145  return complex<Scl<MP_FLOAT> >(x.real()/d,x.imag()/d); }
146 
147 inline complex<Scl<MP_FLOAT> >
148 operator / (const complex<Scl<MP_FLOAT> >& x,const complex<Scl<MP_FLOAT> > y) {
149  complex<Scl<MP_FLOAT> > res(x);
150  res /= y;
151  return complex<Scl<MP_FLOAT> >(res.real(),res.imag()); }
152 
153 ostream & operator<<(ostream & os, const complex<Scl<MP_FLOAT> > & z){
154  os<<"("<< z.real()<< ","<<z.imag()<<")";
155  return(os);
156  }
157 #endif // //_Scl_H_
158 //-----------------------------------------------------------------------------------------------------
159 
160 template<class T> inline void Root_Unity(complex<T> &c, int n) {
161  c = complex<T>(cos(8.0*atan(1.0)/n), sin(8.0*atan(1.0)/n));
162 }
163 
164 template<class T> inline complex<T> pow(const complex<T>& z, int k) {
165  T mod = sqrt(norm(z));
166  if (k == 0) return complex<T> (1, T(0));
167  else
168  if (k == -1)
169  return complex<T>(z.real(), -(z.imag())/mod);
170  else {
171  double argument = k * arg(z);
172  mod = pow(mod,k);
173  return complex<T> (mod*cos(argument), mod*sin(argument));
174  }
175 }
176 
177 //---------------------------------------------------------------------------------------------------
178 /*template<class T>
179 inline boolean operator < (const complex<T>& a,const complex<T> & b)
180 {
181  return norm(a) < norm(b);
182  }*/
183 
184 #endif // // !INCLUDED_COMPLEXH
185 
static double absolute(const double &a)
Definition: RealOf.hpp:59
static void assign(complex< T > &a, const complex< T > &b)
Definition: RealOf.hpp:75
Scl< T > & operator/(const Scl< T > &b1, const Scl< T > &b2)
Definition: BC.hpp:890
MSKcallbackcodee MSKsoltypee MSKprostae MSKsolstae MSKstakeye MSKstakeye MSKstakeye MSKrealt MSKrealt MSKrealt * y
Definition: mosek.h:2689
static void assign(complex< int > &a, const complex< int > &b)
Definition: RealOf.hpp:66
MSKaccmodee MSKint32t MSKsoltypee MSKstakeye MSKrealt * x
Definition: mosek.h:3209
double TYPE
Definition: RealOf.hpp:56
Definition: Complex.hpp:24
MSKint32t k
Definition: mosek.h:2713
Definition: Complex.hpp:26
Definition: Scl.hpp:26
Warning_Value_Type_Not_Defined TYPE
Definition: RealOf.hpp:51
void Root_Unity(complex< T > &c, int n)
Definition: RealOf.hpp:160
Scl< T > & sqrt(const Scl< T > &b)
Definition: BC.hpp:1103
MSKrealt * c
Definition: mosek.h:2678
int TYPE
Definition: RealOf.hpp:65
#define abs(x)
Definition: f2c.H:161
MSKrescodee r
Definition: mosek.h:2321
T TYPE
Definition: RealOf.hpp:74
MSKstreamtypee MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t a
Definition: mosek.h:3833
Definition: RealOf.hpp:50
complex< T > pow(const complex< T > &z, int k)
Definition: RealOf.hpp:164
static void assign(double &a, const complex< double > &b)
Definition: RealOf.hpp:57
void __div_1(T &a, T &b, const T &c, const T &d)
Definition: Complex.hpp:66
Home  |  Download & InstallContributions