ap.cpp
Go to the documentation of this file.
1 #include "svd_si.h"
2 #ifdef HAVE_SVD
3 
4 const double ap::machineepsilon = 5E-16;
5 const double ap::maxrealnumber = 1E300;
6 const double ap::minrealnumber = 1E-300;
7 
8 //
9 // ap::complex operations
10 //
11 bool ap::operator==(const ap::complex& lhs, const ap::complex& rhs)
12 { return lhs.x==rhs.x && lhs.y==rhs.y; }
13 
14 bool ap::operator!=(const ap::complex& lhs, const ap::complex& rhs)
15 { return lhs.x!=rhs.x || lhs.y!=rhs.y; }
16 
18 { return lhs; }
19 
21 { return ap::complex(-lhs.x, -lhs.y); }
22 
23 const ap::complex ap::operator+(const ap::complex& lhs, const ap::complex& rhs)
24 { ap::complex r = lhs; r += rhs; return r; }
25 
26 const ap::complex ap::operator+(const ap::complex& lhs, const double& rhs)
27 { ap::complex r = lhs; r += rhs; return r; }
28 
29 const ap::complex ap::operator+(const double& lhs, const ap::complex& rhs)
30 { ap::complex r = rhs; r += lhs; return r; }
31 
32 const ap::complex ap::operator-(const ap::complex& lhs, const ap::complex& rhs)
33 { ap::complex r = lhs; r -= rhs; return r; }
34 
35 const ap::complex ap::operator-(const ap::complex& lhs, const double& rhs)
36 { ap::complex r = lhs; r -= rhs; return r; }
37 
38 const ap::complex ap::operator-(const double& lhs, const ap::complex& rhs)
39 { ap::complex r = lhs; r -= rhs; return r; }
40 
41 const ap::complex ap::operator*(const ap::complex& lhs, const ap::complex& rhs)
42 { return ap::complex(lhs.x*rhs.x - lhs.y*rhs.y, lhs.x*rhs.y + lhs.y*rhs.x); }
43 
44 const ap::complex ap::operator*(const ap::complex& lhs, const double& rhs)
45 { return ap::complex(lhs.x*rhs, lhs.y*rhs); }
46 
47 const ap::complex ap::operator*(const double& lhs, const ap::complex& rhs)
48 { return ap::complex(lhs*rhs.x, lhs*rhs.y); }
49 
50 const ap::complex ap::operator/(const ap::complex& lhs, const ap::complex& rhs)
51 {
53  double e;
54  double f;
55  if( fabs(rhs.y)<fabs(rhs.x) )
56  {
57  e = rhs.y/rhs.x;
58  f = rhs.x+rhs.y*e;
59  result.x = (lhs.x+lhs.y*e)/f;
60  result.y = (lhs.y-lhs.x*e)/f;
61  }
62  else
63  {
64  e = rhs.x/rhs.y;
65  f = rhs.y+rhs.x*e;
66  result.x = (lhs.y+lhs.x*e)/f;
67  result.y = (-lhs.x+lhs.y*e)/f;
68  }
69  return result;
70 }
71 
72 const ap::complex ap::operator/(const double& lhs, const ap::complex& rhs)
73 {
75  double e;
76  double f;
77  if( fabs(rhs.y)<fabs(rhs.x) )
78  {
79  e = rhs.y/rhs.x;
80  f = rhs.x+rhs.y*e;
81  result.x = lhs/f;
82  result.y = -lhs*e/f;
83  }
84  else
85  {
86  e = rhs.x/rhs.y;
87  f = rhs.y+rhs.x*e;
88  result.x = lhs*e/f;
89  result.y = -lhs/f;
90  }
91  return result;
92 }
93 
94 const ap::complex ap::operator/(const ap::complex& lhs, const double& rhs)
95 { return ap::complex(lhs.x/rhs, lhs.y/rhs); }
96 
97 double ap::abscomplex(const ap::complex &z)
98 {
99  double w;
100  double xabs;
101  double yabs;
102  double v;
103 
104  xabs = fabs(z.x);
105  yabs = fabs(z.y);
106  w = xabs>yabs ? xabs : yabs;
107  v = xabs<yabs ? xabs : yabs;
108  if( v==0 )
109  return w;
110  else
111  {
112  double t = v/w;
113  return w*sqrt(1+t*t);
114  }
115 }
116 
118 { return ap::complex(z.x, -z.y); }
119 
121 { return ap::complex(z.x*z.x-z.y*z.y, 2*z.x*z.y); }
122 
123 //
124 // standard functions
125 //
126 int ap::sign(double x)
127 {
128  if( x>0 ) return 1;
129  if( x<0 ) return -1;
130  return 0;
131 }
132 
134 {
135  int i = rand();
136  while(i==RAND_MAX)
137  i =rand();
138  return double(i)/double(RAND_MAX);
139 }
140 
141 int ap::randominteger(int maxv)
142 { return rand()%maxv; }
143 
144 int ap::round(double x)
145 { return int(floor(x+0.5)); }
146 
147 int ap::trunc(double x)
148 { return int(x>0 ? floor(x) : ceil(x)); }
149 
150 int ap::ifloor(double x)
151 { return int(floor(x)); }
152 
153 int ap::iceil(double x)
154 { return int(ceil(x)); }
155 
156 double ap::pi()
157 { return 3.14159265358979323846; }
158 
159 double ap::sqr(double x)
160 { return x*x; }
161 
162 int ap::maxint(int m1, int m2)
163 {
164  return m1>m2 ? m1 : m2;
165 }
166 
167 int ap::minint(int m1, int m2)
168 {
169  return m1>m2 ? m2 : m1;
170 }
171 
172 double ap::maxreal(double m1, double m2)
173 {
174  return m1>m2 ? m1 : m2;
175 }
176 
177 double ap::minreal(double m1, double m2)
178 {
179  return m1>m2 ? m2 : m1;
180 }
181 #endif
double maxreal(double m1, double m2)
Definition: ap.cpp:172
const complex operator/(const complex &lhs, const complex &rhs)
Definition: ap.cpp:50
double sqr(double x)
Definition: ap.cpp:159
const complex operator-(const complex &lhs)
Definition: ap.cpp:20
double randomreal()
Definition: ap.cpp:133
const bool operator==(const complex &lhs, const complex &rhs)
Definition: ap.cpp:11
const double machineepsilon
Definition: svd_si.h:994
int round(double x)
Definition: ap.cpp:144
int randominteger(int maxv)
Definition: ap.cpp:141
int iceil(double x)
Definition: ap.cpp:153
const signed long floor(const ampf< Precision > &x)
Definition: amp.h:774
const complex operator*(const complex &lhs, const complex &rhs)
Definition: ap.cpp:41
const signed long ceil(const ampf< Precision > &x)
Definition: amp.h:789
double x
Definition: ap.h:98
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:328
int sign(double x)
Definition: ap.cpp:126
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
int minint(int m1, int m2)
Definition: ap.cpp:167
double minreal(double m1, double m2)
Definition: ap.cpp:177
const double minrealnumber
Definition: svd_si.h:996
int maxint(int m1, int m2)
Definition: ap.cpp:162
int trunc(double x)
Definition: ap.cpp:147
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
REvaluation E(1, terms.length(), IntRandom(25))
const complex csqr(const complex &z)
Definition: ap.cpp:120
int ifloor(double x)
Definition: ap.cpp:150
const CanonicalForm & w
Definition: facAbsFact.cc:55
const double maxrealnumber
Definition: svd_si.h:995
Variable x
Definition: cfModGcd.cc:4023
double pi()
Definition: ap.cpp:156
const double abscomplex(const complex &z)
Definition: ap.cpp:97
const complex operator+(const complex &lhs)
Definition: ap.cpp:17
Definition: ap.h:59
double y
Definition: ap.h:98
const bool operator!=(const complex &lhs, const complex &rhs)
Definition: ap.cpp:14
return result
Definition: facAbsBiFact.cc:76
const complex conj(const complex &z)
Definition: ap.cpp:117