Loading...
Searching...
No Matches
ap.cpp
Go to the documentation of this file.
#include "svd_si.h"
#ifdef HAVE_SVD
const double ap::machineepsilon = 5E-16;
const double ap::maxrealnumber = 1E300;
const double ap::minrealnumber = 1E-300;
//
// ap::complex operations
//
bool ap::operator==(const ap::complex& lhs, const ap::complex& rhs)
{ return lhs.x==rhs.x && lhs.y==rhs.y; }
bool ap::operator!=(const ap::complex& lhs, const ap::complex& rhs)
{ return lhs.x!=rhs.x || lhs.y!=rhs.y; }
const ap::complex ap::operator+(const ap::complex& lhs)
{ return lhs; }
const ap::complex ap::operator-(const ap::complex& lhs)
{ return ap::complex(-lhs.x, -lhs.y); }
const ap::complex ap::operator+(const ap::complex& lhs, const ap::complex& rhs)
{ ap::complex r = lhs; r += rhs; return r; }
const ap::complex ap::operator+(const ap::complex& lhs, const double& rhs)
{ ap::complex r = lhs; r += rhs; return r; }
const ap::complex ap::operator+(const double& lhs, const ap::complex& rhs)
{ ap::complex r = rhs; r += lhs; return r; }
const ap::complex ap::operator-(const ap::complex& lhs, const ap::complex& rhs)
{ ap::complex r = lhs; r -= rhs; return r; }
const ap::complex ap::operator-(const ap::complex& lhs, const double& rhs)
{ ap::complex r = lhs; r -= rhs; return r; }
const ap::complex ap::operator-(const double& lhs, const ap::complex& rhs)
{ ap::complex r = lhs; r -= rhs; return r; }
const ap::complex ap::operator*(const ap::complex& lhs, const ap::complex& rhs)
{ return ap::complex(lhs.x*rhs.x - lhs.y*rhs.y, lhs.x*rhs.y + lhs.y*rhs.x); }
const ap::complex ap::operator*(const ap::complex& lhs, const double& rhs)
{ return ap::complex(lhs.x*rhs, lhs.y*rhs); }
const ap::complex ap::operator*(const double& lhs, const ap::complex& rhs)
{ return ap::complex(lhs*rhs.x, lhs*rhs.y); }
const ap::complex ap::operator/(const ap::complex& lhs, const ap::complex& rhs)
{
ap::complex result;
double e;
double f;
if( fabs(rhs.y)<fabs(rhs.x) )
{
e = rhs.y/rhs.x;
f = rhs.x+rhs.y*e;
result.x = (lhs.x+lhs.y*e)/f;
result.y = (lhs.y-lhs.x*e)/f;
}
else
{
e = rhs.x/rhs.y;
f = rhs.y+rhs.x*e;
result.x = (lhs.y+lhs.x*e)/f;
result.y = (-lhs.x+lhs.y*e)/f;
}
return result;
}
const ap::complex ap::operator/(const double& lhs, const ap::complex& rhs)
{
ap::complex result;
double e;
double f;
if( fabs(rhs.y)<fabs(rhs.x) )
{
e = rhs.y/rhs.x;
f = rhs.x+rhs.y*e;
result.x = lhs/f;
result.y = -lhs*e/f;
}
else
{
e = rhs.x/rhs.y;
f = rhs.y+rhs.x*e;
result.x = lhs*e/f;
result.y = -lhs/f;
}
return result;
}
const ap::complex ap::operator/(const ap::complex& lhs, const double& rhs)
{ return ap::complex(lhs.x/rhs, lhs.y/rhs); }
double ap::abscomplex(const ap::complex &z)
{
double w;
double xabs;
double yabs;
double v;
xabs = fabs(z.x);
yabs = fabs(z.y);
w = xabs>yabs ? xabs : yabs;
v = xabs<yabs ? xabs : yabs;
if( v==0 )
return w;
else
{
double t = v/w;
return w*sqrt(1+t*t);
}
}
const ap::complex ap::conj(const ap::complex &z)
{ return ap::complex(z.x, -z.y); }
const ap::complex ap::csqr(const ap::complex &z)
{ return ap::complex(z.x*z.x-z.y*z.y, 2*z.x*z.y); }
//
// standard functions
//
int ap::sign(double x)
{
if( x>0 ) return 1;
if( x<0 ) return -1;
return 0;
}
double ap::randomreal()
{
int i = rand();
while(i==RAND_MAX)
i =rand();
return double(i)/double(RAND_MAX);
}
int ap::randominteger(int maxv)
{ return rand()%maxv; }
int ap::round(double x)
{ return int(floor(x+0.5)); }
int ap::trunc(double x)
{ return int(x>0 ? floor(x) : ceil(x)); }
int ap::ifloor(double x)
{ return int(floor(x)); }
int ap::iceil(double x)
{ return int(ceil(x)); }
double ap::pi()
{ return 3.14159265358979323846; }
double ap::sqr(double x)
{ return x*x; }
int ap::maxint(int m1, int m2)
{
return m1>m2 ? m1 : m2;
}
int ap::minint(int m1, int m2)
{
return m1>m2 ? m2 : m1;
}
double ap::maxreal(double m1, double m2)
{
return m1>m2 ? m1 : m2;
}
double ap::minreal(double m1, double m2)
{
return m1>m2 ? m2 : m1;
}
#endif
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
f
FILE * f
Definition checklibs.c:9
ap::complex
Definition ap.h:60
ap::complex::x
double x
Definition ap.h:100
ap::complex::y
double y
Definition ap.h:100
result
return result
Definition facAbsBiFact.cc:76
E
REvaluation E(1, terms.length(), IntRandom(25))
w
const CanonicalForm & w
Definition facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
sqrt
gmp_float sqrt(const gmp_float &a)
Definition mpr_complex.cc:319
ap::maxint
int maxint(int m1, int m2)
Definition ap.cpp:162
ap::iceil
int iceil(double x)
Definition ap.cpp:153
ap::sqr
double sqr(double x)
Definition ap.cpp:159
ap::operator*
const complex operator*(const complex &lhs, const complex &rhs)
Definition ap.cpp:41
ap::csqr
const complex csqr(const complex &z)
Definition ap.cpp:120
ap::machineepsilon
const double machineepsilon
Definition svd_si.h:995
ap::round
int round(double x)
Definition ap.cpp:144
ap::trunc
int trunc(double x)
Definition ap.cpp:147
ap::minrealnumber
const double minrealnumber
Definition svd_si.h:997
ap::randomreal
double randomreal()
Definition ap.cpp:133
ap::randominteger
int randominteger(int maxv)
Definition ap.cpp:141
ap::sign
int sign(double x)
Definition ap.cpp:126
ap::maxreal
double maxreal(double m1, double m2)
Definition ap.cpp:172
ap::abscomplex
const double abscomplex(const complex &z)
Definition ap.cpp:97
ap::operator!=
const bool operator!=(const complex &lhs, const complex &rhs)
Definition ap.cpp:14
ap::minreal
double minreal(double m1, double m2)
Definition ap.cpp:177
ap::minint
int minint(int m1, int m2)
Definition ap.cpp:167
ap::pi
double pi()
Definition ap.cpp:156
ap::conj
const complex conj(const complex &z)
Definition ap.cpp:117
ap::operator+
const complex operator+(const complex &lhs)
Definition ap.cpp:17
ap::ifloor
int ifloor(double x)
Definition ap.cpp:150
ap::operator/
const complex operator/(const complex &lhs, const complex &rhs)
Definition ap.cpp:50
ap::maxrealnumber
const double maxrealnumber
Definition svd_si.h:996
ap::operator==
const bool operator==(const complex &lhs, const complex &rhs)
Definition ap.cpp:11
ap::operator-
const complex operator-(const complex &lhs)
Definition ap.cpp:20
svd_si.h