Loading...
Searching...
No Matches
mpr_complex.h
Go to the documentation of this file.
#ifndef MPR_COMPLEX_H
#define MPR_COMPLEX_H
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT - multipolynomial resultants - real floating-point numbers using gmp
* and complex numbers based on pairs of real floating-point numbers
*
*/
//-> include & define stuff
// must have gmp version >= 2
#include "coeffs/si_gmp.h"
#include "coeffs/mpr_global.h"
#define ZTOF 1
#define QTOF 2
#define RTOF 3
#define CTOF 4
void setGMPFloatDigits( size_t digits, size_t rest );
//-> class gmp_float
/**
* @short wrapper class for GNU Multi Precision Floats
*/
class gmp_float;
char *floatToStr( const gmp_float & r, const unsigned int oprec );
class gmp_float
{
public:
gmp_float( const int v = 0 )
{
mpf_init_set_si( t, (long)v );
}
gmp_float( const long v )
{
mpf_init_set_si( t, v );
}
gmp_float( const mprfloat v ) // double
{
mpf_init_set_d( t, v );
}
gmp_float( const mpf_t v )
{
mpf_init_set( t, v );
}
gmp_float( const mpz_t v ) // gnu mp Z
{
mpf_init( t );
mpf_set_z( t, v );
}
gmp_float( const gmp_float & v ) // copy constructor
{
mpf_init_set( t, v.t );
}
~gmp_float()
{
mpf_clear( t );
}
inline gmp_float & operator = ( const gmp_float & a )
{
mpf_set( t, a.t );
return *this;
};
inline gmp_float & operator = ( const mpz_t & a )
{
mpf_set_z( t, a );
return *this;
};
inline gmp_float & operator = ( const mprfloat a )
{
mpf_set_d( t, (double) a );
return *this;
};
inline gmp_float & operator = ( const long a )
{
mpf_set_d( t, (double) a );
return *this;
};
gmp_float & operator += ( const gmp_float & a );
gmp_float & operator -= ( const gmp_float & a );
inline gmp_float & operator *= ( const gmp_float & a )
{
mpf_mul( t, t, a.t );
return *this;
};
inline gmp_float & operator /= ( const gmp_float & a )
{
mpf_div( t, t, a.t );
return *this;
};
inline gmp_float & neg ( ) { mpf_neg(t,t); return *this; };
friend gmp_float operator + ( const gmp_float & a, const gmp_float & b );
friend gmp_float operator - ( const gmp_float & a, const gmp_float & b );
friend gmp_float operator * ( const gmp_float & a, const gmp_float & b );
friend gmp_float operator / ( const gmp_float & a, const gmp_float & b );
inline gmp_float operator ^ ( const int exp ) const
{
mpf_t b;
mpf_init(b);
mpf_pow_ui( b, this->t, (unsigned long)exp );
gmp_float res=gmp_float(b);
mpf_clear(b);
return res;
};
friend bool operator == ( const gmp_float & a, const gmp_float & b );
friend bool operator > ( const gmp_float & a, const gmp_float & b );
friend bool operator < ( const gmp_float & a, const gmp_float & b );
friend bool operator >= ( const gmp_float & a, const gmp_float & b );
friend bool operator <= ( const gmp_float & a, const gmp_float & b );
friend gmp_float operator - ( const gmp_float & a );
inline int sign() // t>0:+1, t==0:0, t<0:-1
{ return mpf_sgn( t ); };
bool isZero() const; // t == 0 ?
bool isOne() const; // t == 1 ?
bool isMOne() const; // t == -1 ?
void setFromStr(const char * in );
// access
inline const mpf_t *mpfp() const { return &t; };
inline mpf_t *_mpfp() { return &t; };
inline operator double() { return mpf_get_d( t ); };
inline operator double() const { return mpf_get_d( t ); };
#if 0
inline operator int() { return (int)mpf_get_d( t ); };
inline operator int() const { return (int)mpf_get_d( t ); };
//#else
inline operator int() const
{ if (mpf_fits_sint_p(t))
{ return (int)mpf_get_si( t ); }
return 0;
};
#endif
public:
mpf_t t;
};
// built-in functions of GMP
gmp_float abs( const gmp_float & );
gmp_float sqrt( const gmp_float & );
gmp_float hypot( const gmp_float &, const gmp_float & );
//gmp_float pow( const gmp_float &, int & );
// simulated functions using double functions
gmp_float sin( const gmp_float & );
gmp_float cos( const gmp_float & );
gmp_float log( const gmp_float & );
gmp_float exp( const gmp_float & );
gmp_float max( const gmp_float &, const gmp_float & );
gmp_float numberToFloat( number num, const coeffs src );
gmp_float numberFieldToFloat( number num, int src );
//char *floatToStr( const gmp_float & r, const unsigned int oprec );
//<-
//-> class gmp_complex
/**
* @short gmp_complex numbers based on
*/
class gmp_complex
{
private:
gmp_float r, i;
public:
gmp_complex( const gmp_float re= 0.0, const gmp_float im= 0.0 )
{
r= re;
i= im;
}
gmp_complex( const mprfloat re, const mprfloat im = 0.0 )
{
r= re;
i= im;
}
gmp_complex( const long re, const long im )
{
r= re;
i= im;
}
gmp_complex( const gmp_complex & v )
{
r= v.r;
i= v.i;
}
~gmp_complex() {}
gmp_complex & neg ( );
friend gmp_complex operator + ( const gmp_complex & a, const gmp_complex & b );
friend gmp_complex operator - ( const gmp_complex & a, const gmp_complex & b );
friend gmp_complex operator * ( const gmp_complex & a, const gmp_complex & b );
friend gmp_complex operator / ( const gmp_complex & a, const gmp_complex & b );
// gmp_complex <operator> real
inline friend gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d );
inline friend gmp_complex operator - ( const gmp_complex & a, const gmp_float b_d );
inline friend gmp_complex operator * ( const gmp_complex & a, const gmp_float b_d );
inline friend gmp_complex operator / ( const gmp_complex & a, const gmp_float b_d );
gmp_complex & operator += ( const gmp_complex & a );
gmp_complex & operator -= ( const gmp_complex & a );
gmp_complex & operator *= ( const gmp_complex & a );
gmp_complex & operator /= ( const gmp_complex & a );
inline friend bool operator == ( const gmp_complex & a, const gmp_complex & b );
inline friend bool operator > ( const gmp_complex & a, const gmp_complex & b );
inline friend bool operator < ( const gmp_complex & a, const gmp_complex & b );
inline friend bool operator >= ( const gmp_complex & a, const gmp_complex & b );
inline friend bool operator <= ( const gmp_complex & a, const gmp_complex & b );
inline gmp_complex & operator = ( const gmp_complex & a );
inline gmp_complex & operator = ( const gmp_float & f );
// access to real and imaginary part
inline gmp_float real() const { return r; }
inline gmp_float imag() const { return i; }
inline void real( gmp_float val ) { r = val; }
inline void imag( gmp_float val ) { i = val; }
inline bool isZero() { return (r.isZero() && i.isZero()); }
void SmallToZero();
};
// <gmp_complex> = <gmp_complex> operator <gmp_float>
//
inline gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d )
{
return gmp_complex( a.r + b_d, a.i );
}
inline gmp_complex operator - ( const gmp_complex & a, const gmp_float b_d )
{
return gmp_complex( a.r - b_d, a.i );
}
inline gmp_complex operator * ( const gmp_complex & a, const gmp_float b_d )
{
return gmp_complex( a.r * b_d, a.i * b_d );
}
inline gmp_complex operator / ( const gmp_complex & a, const gmp_float b_d )
{
return gmp_complex( a.r / b_d, a.i / b_d );
}
// <gmp_complex> == <gmp_complex> ?
inline bool operator == ( const gmp_complex & a, const gmp_complex & b )
{
return ( b.real() == a.real() ) && ( b.imag() == a.imag() );
}
inline bool operator > ( const gmp_complex & a, const gmp_complex & b )
{
return ( a.real() > b.real() );
}
inline bool operator < ( const gmp_complex & a, const gmp_complex & b )
{
return ( a.real() < b.real() );
}
inline bool operator >= ( const gmp_complex & a, const gmp_complex & b )
{
return ( a.real() >= b.real() );
}
inline bool operator <= ( const gmp_complex & a, const gmp_complex & b )
{
return ( a.real() <= b.real() );
}
// <gmp_complex> = <gmp_complex>
inline gmp_complex & gmp_complex::operator = ( const gmp_complex & a )
{
r= a.r;
i= a.i;
return *this;
}
// <gmp_complex> = <gmp_complex>
inline gmp_complex & gmp_complex::operator = ( const gmp_float & f )
{
r= f;
i= (long int)0;
return *this;
}
// Returns absolute value of a gmp_complex number
//
inline gmp_float abs( const gmp_complex & c )
{
return hypot(c.real(),c.imag());
}
gmp_complex sqrt( const gmp_complex & x );
inline gmp_complex numberToComplex( number num, const coeffs r )
{
if (nCoeff_is_long_C(r))
{
return *(gmp_complex*)num;
}
else
{
return gmp_complex( numberToFloat(num, r) );
}
}
char *complexToStr( gmp_complex & c, const unsigned int oprec, const coeffs src );
//<-
bool complexNearZero( gmp_complex * c, int digits );
#endif /* MPR_COMPLEX_H */
// local Variables: ***
// folded-file: t ***
// compile-command-1: "make installg" ***
// compile-command-2: "make install" ***
// End: ***
num
CanonicalForm num(const CanonicalForm &f)
Definition canonicalform.h:337
x
Variable x
Definition cfModGcd.cc:4090
b
CanonicalForm b
Definition cfModGcd.cc:4111
f
FILE * f
Definition checklibs.c:9
gmp_complex
gmp_complex numbers based on
Definition mpr_complex.h:181
gmp_complex::operator<
friend bool operator<(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:275
gmp_complex::i
gmp_float i
Definition mpr_complex.h:183
gmp_complex::gmp_complex
gmp_complex(const mprfloat re, const mprfloat im=0.0)
Definition mpr_complex.h:191
gmp_complex::operator*
friend gmp_complex operator*(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.cc:616
gmp_complex::operator==
friend bool operator==(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:267
gmp_complex::gmp_complex
gmp_complex(const gmp_complex &v)
Definition mpr_complex.h:201
gmp_complex::imag
gmp_float imag() const
Definition mpr_complex.h:237
gmp_complex::real
void real(gmp_float val)
Definition mpr_complex.h:239
gmp_complex::~gmp_complex
~gmp_complex()
Definition mpr_complex.h:206
gmp_complex::operator+
friend gmp_complex operator+(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.cc:608
gmp_complex::gmp_complex
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition mpr_complex.h:186
gmp_complex::operator>
friend bool operator>(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:271
gmp_complex::operator<=
friend bool operator<=(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:283
gmp_complex::operator*=
gmp_complex & operator*=(const gmp_complex &a)
Definition mpr_complex.cc:642
gmp_complex::operator/=
gmp_complex & operator/=(const gmp_complex &a)
Definition mpr_complex.cc:655
gmp_complex::SmallToZero
void SmallToZero()
Definition mpr_complex.cc:773
gmp_complex::operator-
friend gmp_complex operator-(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.cc:612
gmp_complex::operator=
gmp_complex & operator=(const gmp_complex &a)
Definition mpr_complex.h:290
gmp_complex::operator/
friend gmp_complex operator/(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.cc:621
gmp_complex::gmp_complex
gmp_complex(const long re, const long im)
Definition mpr_complex.h:196
gmp_complex::neg
gmp_complex & neg()
Definition mpr_complex.cc:649
gmp_complex::operator+=
gmp_complex & operator+=(const gmp_complex &a)
Definition mpr_complex.cc:630
gmp_complex::imag
void imag(gmp_float val)
Definition mpr_complex.h:240
gmp_complex::operator>=
friend bool operator>=(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:279
gmp_complex::r
gmp_float r
Definition mpr_complex.h:183
gmp_complex::real
gmp_float real() const
Definition mpr_complex.h:236
gmp_complex::operator-=
gmp_complex & operator-=(const gmp_complex &a)
Definition mpr_complex.cc:636
gmp_complex::isZero
bool isZero()
Definition mpr_complex.h:243
gmp_float
Definition mpr_complex.h:32
gmp_float::setFromStr
void setFromStr(const char *in)
Definition mpr_complex.cc:78
gmp_float::gmp_float
gmp_float(const int v=0)
Definition mpr_complex.h:34
gmp_float::isOne
bool isOne() const
Definition mpr_complex.cc:257
gmp_float::gmp_float
gmp_float(const mprfloat v)
Definition mpr_complex.h:42
gmp_float::~gmp_float
~gmp_float()
Definition mpr_complex.h:60
gmp_float::operator^
gmp_float operator^(const int exp) const
Definition mpr_complex.h:107
gmp_float::operator*
friend gmp_float operator*(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:179
gmp_float::operator<
friend bool operator<(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:292
gmp_float::operator<=
friend bool operator<=(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:300
gmp_float::sign
int sign()
Definition mpr_complex.h:125
gmp_float::gmp_float
gmp_float(const gmp_float &v)
Definition mpr_complex.h:55
gmp_float::t
mpf_t t
Definition mpr_complex.h:153
gmp_float::isMOne
bool isMOne() const
Definition mpr_complex.cc:273
gmp_float::operator-=
gmp_float & operator-=(const gmp_float &a)
Definition mpr_complex.cc:214
gmp_float::_mpfp
mpf_t * _mpfp()
Definition mpr_complex.h:136
gmp_float::operator/=
gmp_float & operator/=(const gmp_float &a)
Definition mpr_complex.h:94
gmp_float::operator-
friend gmp_float operator-(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:173
gmp_float::operator+
friend gmp_float operator+(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:167
gmp_float::operator+=
gmp_float & operator+=(const gmp_float &a)
Definition mpr_complex.cc:193
gmp_float::neg
gmp_float & neg()
Definition mpr_complex.h:100
gmp_float::operator=
gmp_float & operator=(const gmp_float &a)
Definition mpr_complex.h:65
gmp_float::operator==
friend bool operator==(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:237
gmp_float::isZero
bool isZero() const
Definition mpr_complex.cc:252
gmp_float::mpfp
const mpf_t * mpfp() const
Definition mpr_complex.h:135
gmp_float::operator*=
gmp_float & operator*=(const gmp_float &a)
Definition mpr_complex.h:88
gmp_float::gmp_float
gmp_float(const mpz_t v)
Definition mpr_complex.h:50
gmp_float::operator/
friend gmp_float operator/(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:185
gmp_float::operator>=
friend bool operator>=(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:296
gmp_float::gmp_float
gmp_float(const long v)
Definition mpr_complex.h:38
gmp_float::operator>
friend bool operator>(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:288
gmp_float::gmp_float
gmp_float(const mpf_t v)
Definition mpr_complex.h:46
nCoeff_is_long_C
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition coeffs.h:889
res
CanonicalForm res
Definition facAbsFact.cc:60
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
operator<
bool operator<(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:275
operator==
bool operator==(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:267
max
gmp_float max(const gmp_float &, const gmp_float &)
Definition mpr_complex.cc:354
complexToStr
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
Definition mpr_complex.cc:693
exp
gmp_float exp(const gmp_float &)
Definition mpr_complex.cc:349
hypot
gmp_float hypot(const gmp_float &, const gmp_float &)
Definition mpr_complex.cc:340
operator/
gmp_complex operator/(const gmp_complex &a, const gmp_float b_d)
Definition mpr_complex.h:261
operator>
bool operator>(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:271
operator<=
bool operator<=(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:283
log
gmp_float log(const gmp_float &)
Definition mpr_complex.cc:335
operator+
gmp_complex operator+(const gmp_complex &a, const gmp_float b_d)
Definition mpr_complex.h:249
floatToStr
char * floatToStr(const gmp_float &r, const unsigned int oprec)
Definition mpr_complex.cc:567
complexNearZero
bool complexNearZero(gmp_complex *c, int digits)
Definition mpr_complex.cc:754
operator*
gmp_complex operator*(const gmp_complex &a, const gmp_float b_d)
Definition mpr_complex.h:257
cos
gmp_float cos(const gmp_float &)
Definition mpr_complex.cc:330
sqrt
gmp_float sqrt(const gmp_float &)
Definition mpr_complex.cc:319
numberToFloat
gmp_float numberToFloat(number num, const coeffs src)
Definition mpr_complex.cc:364
operator>=
bool operator>=(const gmp_complex &a, const gmp_complex &b)
Definition mpr_complex.h:279
numberToComplex
gmp_complex numberToComplex(number num, const coeffs r)
Definition mpr_complex.h:314
numberFieldToFloat
gmp_float numberFieldToFloat(number num, int src)
Definition mpr_complex.cc:430
operator-
gmp_complex operator-(const gmp_complex &a, const gmp_float b_d)
Definition mpr_complex.h:253
abs
gmp_float abs(const gmp_float &)
Definition mpr_complex.cc:313
sin
gmp_float sin(const gmp_float &)
Definition mpr_complex.cc:325
setGMPFloatDigits
void setGMPFloatDigits(size_t digits, size_t rest)
Set size of mantissa digits - the number of output digits (basis 10) the size of mantissa consists of...
Definition mpr_complex.cc:60
mpr_global.h
mprfloat
double mprfloat
Definition mpr_global.h:17
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
si_gmp.h