My Project
Loading...
Searching...
No Matches
ap.cpp
Go to the documentation of this file.
1#include "svd_si.h"
2#ifdef HAVE_SVD
3
4const double ap::machineepsilon = 5E-16;
5const double ap::maxrealnumber = 1E300;
6const double ap::minrealnumber = 1E-300;
7
8//
9// ap::complex operations
10//
11bool ap::operator==(const ap::complex& lhs, const ap::complex& rhs)
12{ return lhs.x==rhs.x && lhs.y==rhs.y; }
13
14bool 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
23const ap::complex ap::operator+(const ap::complex& lhs, const ap::complex& rhs)
24{ ap::complex r = lhs; r += rhs; return r; }
25
26const ap::complex ap::operator+(const ap::complex& lhs, const double& rhs)
27{ ap::complex r = lhs; r += rhs; return r; }
28
29const ap::complex ap::operator+(const double& lhs, const ap::complex& rhs)
30{ ap::complex r = rhs; r += lhs; return r; }
31
32const ap::complex ap::operator-(const ap::complex& lhs, const ap::complex& rhs)
33{ ap::complex r = lhs; r -= rhs; return r; }
34
35const ap::complex ap::operator-(const ap::complex& lhs, const double& rhs)
36{ ap::complex r = lhs; r -= rhs; return r; }
37
38const ap::complex ap::operator-(const double& lhs, const ap::complex& rhs)
39{ ap::complex r = lhs; r -= rhs; return r; }
40
41const 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
44const ap::complex ap::operator*(const ap::complex& lhs, const double& rhs)
45{ return ap::complex(lhs.x*rhs, lhs.y*rhs); }
46
47const ap::complex ap::operator*(const double& lhs, const ap::complex& rhs)
48{ return ap::complex(lhs*rhs.x, lhs*rhs.y); }
49
50const 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
72const 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
94const ap::complex ap::operator/(const ap::complex& lhs, const double& rhs)
95{ return ap::complex(lhs.x/rhs, lhs.y/rhs); }
96
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//
126int 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
141int ap::randominteger(int maxv)
142{ return rand()%maxv; }
143
144int ap::round(double x)
145{ return int(floor(x+0.5)); }
146
147int ap::trunc(double x)
148{ return int(x>0 ? floor(x) : ceil(x)); }
149
150int ap::ifloor(double x)
151{ return int(floor(x)); }
152
153int ap::iceil(double x)
154{ return int(ceil(x)); }
155
156double ap::pi()
157{ return 3.14159265358979323846; }
158
159double ap::sqr(double x)
160{ return x*x; }
161
162int ap::maxint(int m1, int m2)
163{
164 return m1>m2 ? m1 : m2;
165}
166
167int ap::minint(int m1, int m2)
168{
169 return m1>m2 ? m2 : m1;
170}
171
172double ap::maxreal(double m1, double m2)
173{
174 return m1>m2 ? m1 : m2;
175}
176
177double ap::minreal(double m1, double m2)
178{
179 return m1>m2 ? m2 : m1;
180}
181#endif
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4082
FILE * f
Definition: checklibs.c:9
Definition: ap.h:60
double x
Definition: ap.h:100
double y
Definition: ap.h:100
return result
Definition: facAbsBiFact.cc:75
REvaluation E(1, terms.length(), IntRandom(25))
const CanonicalForm & w
Definition: facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:327
int maxint(int m1, int m2)
Definition: ap.cpp:162
int iceil(double x)
Definition: ap.cpp:153
double sqr(double x)
Definition: ap.cpp:159
const complex operator*(const complex &lhs, const complex &rhs)
Definition: ap.cpp:41
const complex csqr(const complex &z)
Definition: ap.cpp:120
const double machineepsilon
Definition: svd_si.h:995
int round(double x)
Definition: ap.cpp:144
int trunc(double x)
Definition: ap.cpp:147
const double minrealnumber
Definition: svd_si.h:997
double randomreal()
Definition: ap.cpp:133
int randominteger(int maxv)
Definition: ap.cpp:141
int sign(double x)
Definition: ap.cpp:126
double maxreal(double m1, double m2)
Definition: ap.cpp:172
const double abscomplex(const complex &z)
Definition: ap.cpp:97
const bool operator!=(const complex &lhs, const complex &rhs)
Definition: ap.cpp:14
double minreal(double m1, double m2)
Definition: ap.cpp:177
int minint(int m1, int m2)
Definition: ap.cpp:167
double pi()
Definition: ap.cpp:156
const complex conj(const complex &z)
Definition: ap.cpp:117
const complex operator+(const complex &lhs)
Definition: ap.cpp:17
int ifloor(double x)
Definition: ap.cpp:150
const complex operator/(const complex &lhs, const complex &rhs)
Definition: ap.cpp:50
const double maxrealnumber
Definition: svd_si.h:996
const bool operator==(const complex &lhs, const complex &rhs)
Definition: ap.cpp:11
const complex operator-(const complex &lhs)
Definition: ap.cpp:20