My Project
Loading...
Searching...
No Matches
mpr_complex.h
Go to the documentation of this file.
1#ifndef MPR_COMPLEX_H
2#define MPR_COMPLEX_H
3/****************************************
4* Computer Algebra System SINGULAR *
5****************************************/
6
7/*
8* ABSTRACT - multipolynomial resultants - real floating-point numbers using gmp
9* and complex numbers based on pairs of real floating-point numbers
10*
11*/
12
13//-> include & define stuff
14// must have gmp version >= 2
15#include "coeffs/si_gmp.h"
16#include "coeffs/mpr_global.h"
17
18#define ZTOF 1
19#define QTOF 2
20#define RTOF 3
21#define CTOF 4
22
23void setGMPFloatDigits( size_t digits, size_t rest );
24
25//-> class gmp_float
26/**
27 * @short wrapper class for GNU Multi Precision Floats
28 */
29class gmp_float;
30char *floatToStr( const gmp_float & r, const unsigned int oprec );
32{
33public:
34 gmp_float( const int v = 0 )
35 {
36 mpf_init_set_si( t, (long)v );
37 }
38 gmp_float( const long v )
39 {
40 mpf_init_set_si( t, v );
41 }
42 gmp_float( const mprfloat v ) // double
43 {
44 mpf_init_set_d( t, v );
45 }
46 gmp_float( const mpf_t v )
47 {
48 mpf_init_set( t, v );
49 }
50 gmp_float( const mpz_t v ) // gnu mp Z
51 {
52 mpf_init( t );
53 mpf_set_z( t, v );
54 }
55 gmp_float( const gmp_float & v ) // copy constructor
56 {
57 mpf_init_set( t, v.t );
58 }
59
61 {
62 mpf_clear( t );
63 }
64
65 inline gmp_float & operator = ( const gmp_float & a )
66 {
67 mpf_set( t, a.t );
68 return *this;
69 };
70 inline gmp_float & operator = ( const mpz_t & a )
71 {
72 mpf_set_z( t, a );
73 return *this;
74 };
75 inline gmp_float & operator = ( const mprfloat a )
76 {
77 mpf_set_d( t, (double) a );
78 return *this;
79 };
80 inline gmp_float & operator = ( const long a )
81 {
82 mpf_set_d( t, (double) a );
83 return *this;
84 };
85
86 gmp_float & operator += ( const gmp_float & a );
87 gmp_float & operator -= ( const gmp_float & a );
88 inline gmp_float & operator *= ( const gmp_float & a )
89 {
90 mpf_mul( t, t, a.t );
91 return *this;
92 };
93
94 inline gmp_float & operator /= ( const gmp_float & a )
95 {
96 mpf_div( t, t, a.t );
97 return *this;
98 };
99
100 inline gmp_float & neg ( ) { mpf_neg(t,t); return *this; };
101
102 friend gmp_float operator + ( const gmp_float & a, const gmp_float & b );
103 friend gmp_float operator - ( const gmp_float & a, const gmp_float & b );
104 friend gmp_float operator * ( const gmp_float & a, const gmp_float & b );
105 friend gmp_float operator / ( const gmp_float & a, const gmp_float & b );
106
107 inline gmp_float operator ^ ( const int exp ) const
108 {
109 mpf_t b;
110 mpf_init(b);
111 mpf_pow_ui( b, this->t, (unsigned long)exp );
113 mpf_clear(b);
114 return res;
115 };
116
117 friend bool operator == ( const gmp_float & a, const gmp_float & b );
118 friend bool operator > ( const gmp_float & a, const gmp_float & b );
119 friend bool operator < ( const gmp_float & a, const gmp_float & b );
120 friend bool operator >= ( const gmp_float & a, const gmp_float & b );
121 friend bool operator <= ( const gmp_float & a, const gmp_float & b );
122
123 friend gmp_float operator - ( const gmp_float & a );
124
125 inline int sign() // t>0:+1, t==0:0, t<0:-1
126 { return mpf_sgn( t ); };
127
128 bool isZero() const; // t == 0 ?
129 bool isOne() const; // t == 1 ?
130 bool isMOne() const; // t == -1 ?
131
132 void setFromStr(const char * in );
133
134 // access
135 inline const mpf_t *mpfp() const { return &t; };
136 inline mpf_t *_mpfp() { return &t; };
137
138 inline operator double() { return mpf_get_d( t ); };
139 inline operator double() const { return mpf_get_d( t ); };
140
141#if 0
142 inline operator int() { return (int)mpf_get_d( t ); };
143 inline operator int() const { return (int)mpf_get_d( t ); };
144//#else
145 inline operator int() const
146 { if (mpf_fits_sint_p(t))
147 { return (int)mpf_get_si( t ); }
148 return 0;
149 };
150#endif
151
152public:
153 mpf_t t;
154};
155
156
157// built-in functions of GMP
158gmp_float abs( const gmp_float & );
159gmp_float sqrt( const gmp_float & );
160gmp_float hypot( const gmp_float &, const gmp_float & );
161//gmp_float pow( const gmp_float &, int & );
162
163// simulated functions using double functions
164gmp_float sin( const gmp_float & );
165gmp_float cos( const gmp_float & );
166gmp_float log( const gmp_float & );
167gmp_float exp( const gmp_float & );
168
169gmp_float max( const gmp_float &, const gmp_float & );
170
171gmp_float numberToFloat( number num, const coeffs src );
172gmp_float numberFieldToFloat( number num, int src );
173//char *floatToStr( const gmp_float & r, const unsigned int oprec );
174//<-
175
176//-> class gmp_complex
177/**
178 * @short gmp_complex numbers based on
179 */
181{
182private:
184
185public:
186 gmp_complex( const gmp_float re= 0.0, const gmp_float im= 0.0 )
187 {
188 r= re;
189 i= im;
190 }
191 gmp_complex( const mprfloat re, const mprfloat im = 0.0 )
192 {
193 r= re;
194 i= im;
195 }
196 gmp_complex( const long re, const long im )
197 {
198 r= re;
199 i= im;
200 }
202 {
203 r= v.r;
204 i= v.i;
205 }
207
208 gmp_complex & neg ( );
209
210 friend gmp_complex operator + ( const gmp_complex & a, const gmp_complex & b );
211 friend gmp_complex operator - ( const gmp_complex & a, const gmp_complex & b );
212 friend gmp_complex operator * ( const gmp_complex & a, const gmp_complex & b );
213 friend gmp_complex operator / ( const gmp_complex & a, const gmp_complex & b );
214
215 // gmp_complex <operator> real
216 inline friend gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d );
217 inline friend gmp_complex operator - ( const gmp_complex & a, const gmp_float b_d );
218 inline friend gmp_complex operator * ( const gmp_complex & a, const gmp_float b_d );
219 inline friend gmp_complex operator / ( const gmp_complex & a, const gmp_float b_d );
220
221 gmp_complex & operator += ( const gmp_complex & a );
222 gmp_complex & operator -= ( const gmp_complex & a );
223 gmp_complex & operator *= ( const gmp_complex & a );
224 gmp_complex & operator /= ( const gmp_complex & a );
225
226 inline friend bool operator == ( const gmp_complex & a, const gmp_complex & b );
227 inline friend bool operator > ( const gmp_complex & a, const gmp_complex & b );
228 inline friend bool operator < ( const gmp_complex & a, const gmp_complex & b );
229 inline friend bool operator >= ( const gmp_complex & a, const gmp_complex & b );
230 inline friend bool operator <= ( const gmp_complex & a, const gmp_complex & b );
231
232 inline gmp_complex & operator = ( const gmp_complex & a );
233 inline gmp_complex & operator = ( const gmp_float & f );
234
235 // access to real and imaginary part
236 inline gmp_float real() const { return r; }
237 inline gmp_float imag() const { return i; }
238
239 inline void real( gmp_float val ) { r = val; }
240 inline void imag( gmp_float val ) { i = val; }
241
242
243 inline bool isZero() { return (r.isZero() && i.isZero()); }
244 void SmallToZero();
245};
246
247// <gmp_complex> = <gmp_complex> operator <gmp_float>
248//
249inline gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d )
250{
251 return gmp_complex( a.r + b_d, a.i );
252}
253inline gmp_complex operator - ( const gmp_complex & a, const gmp_float b_d )
254{
255 return gmp_complex( a.r - b_d, a.i );
256}
257inline gmp_complex operator * ( const gmp_complex & a, const gmp_float b_d )
258{
259 return gmp_complex( a.r * b_d, a.i * b_d );
260}
261inline gmp_complex operator / ( const gmp_complex & a, const gmp_float b_d )
262{
263 return gmp_complex( a.r / b_d, a.i / b_d );
264}
265
266// <gmp_complex> == <gmp_complex> ?
267inline bool operator == ( const gmp_complex & a, const gmp_complex & b )
268{
269 return ( b.real() == a.real() ) && ( b.imag() == a.imag() );
270}
271inline bool operator > ( const gmp_complex & a, const gmp_complex & b )
272{
273 return ( a.real() > b.real() );
274}
275inline bool operator < ( const gmp_complex & a, const gmp_complex & b )
276{
277 return ( a.real() < b.real() );
278}
279inline bool operator >= ( const gmp_complex & a, const gmp_complex & b )
280{
281 return ( a.real() >= b.real() );
282}
283inline bool operator <= ( const gmp_complex & a, const gmp_complex & b )
284{
285 return ( a.real() <= b.real() );
286}
287
288
289// <gmp_complex> = <gmp_complex>
291{
292 r= a.r;
293 i= a.i;
294 return *this;
295}
296
297// <gmp_complex> = <gmp_complex>
299{
300 r= f;
301 i= (long int)0;
302 return *this;
303}
304
305// Returns absolute value of a gmp_complex number
306//
307inline gmp_float abs( const gmp_complex & c )
308{
309 return hypot(c.real(),c.imag());
310}
311
312gmp_complex sqrt( const gmp_complex & x );
313
314inline gmp_complex numberToComplex( number num, const coeffs r )
315{
316 if (nCoeff_is_long_C(r))
317 {
318 return *(gmp_complex*)num;
319 }
320 else
321 {
322 return gmp_complex( numberToFloat(num, r) );
323 }
324}
325
326char *complexToStr( gmp_complex & c, const unsigned int oprec, const coeffs src );
327//<-
328
329bool complexNearZero( gmp_complex * c, int digits );
330
331#endif /* MPR_COMPLEX_H */
332
333// local Variables: ***
334// folded-file: t ***
335// compile-command-1: "make installg" ***
336// compile-command-2: "make install" ***
337// End: ***
CanonicalForm num(const CanonicalForm &f)
Variable x
Definition cfModGcd.cc:4090
CanonicalForm b
Definition cfModGcd.cc:4111
FILE * f
Definition checklibs.c:9
gmp_complex numbers based on
friend bool operator<(const gmp_complex &a, const gmp_complex &b)
gmp_float i
gmp_complex(const mprfloat re, const mprfloat im=0.0)
friend gmp_complex operator*(const gmp_complex &a, const gmp_complex &b)
friend bool operator==(const gmp_complex &a, const gmp_complex &b)
gmp_complex(const gmp_complex &v)
gmp_float imag() const
void real(gmp_float val)
friend gmp_complex operator+(const gmp_complex &a, const gmp_complex &b)
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
friend bool operator>(const gmp_complex &a, const gmp_complex &b)
friend bool operator<=(const gmp_complex &a, const gmp_complex &b)
gmp_complex & operator*=(const gmp_complex &a)
gmp_complex & operator/=(const gmp_complex &a)
void SmallToZero()
friend gmp_complex operator-(const gmp_complex &a, const gmp_complex &b)
gmp_complex & operator=(const gmp_complex &a)
friend gmp_complex operator/(const gmp_complex &a, const gmp_complex &b)
gmp_complex(const long re, const long im)
gmp_complex & neg()
gmp_complex & operator+=(const gmp_complex &a)
void imag(gmp_float val)
friend bool operator>=(const gmp_complex &a, const gmp_complex &b)
gmp_float r
gmp_float real() const
gmp_complex & operator-=(const gmp_complex &a)
bool isZero()
void setFromStr(const char *in)
gmp_float(const int v=0)
Definition mpr_complex.h:34
bool isOne() const
gmp_float(const mprfloat v)
Definition mpr_complex.h:42
gmp_float operator^(const int exp) const
friend gmp_float 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)
gmp_float(const gmp_float &v)
Definition mpr_complex.h:55
bool isMOne() const
gmp_float & operator-=(const gmp_float &a)
mpf_t * _mpfp()
gmp_float & operator/=(const gmp_float &a)
Definition mpr_complex.h:94
friend gmp_float operator-(const gmp_float &a, const gmp_float &b)
friend gmp_float operator+(const gmp_float &a, const gmp_float &b)
gmp_float & operator+=(const gmp_float &a)
gmp_float & neg()
gmp_float & operator=(const gmp_float &a)
Definition mpr_complex.h:65
friend bool operator==(const gmp_float &a, const gmp_float &b)
bool isZero() const
const mpf_t * mpfp() const
gmp_float & operator*=(const gmp_float &a)
Definition mpr_complex.h:88
gmp_float(const mpz_t v)
Definition mpr_complex.h:50
friend gmp_float operator/(const gmp_float &a, const gmp_float &b)
friend bool operator>=(const gmp_float &a, const gmp_float &b)
gmp_float(const long v)
Definition mpr_complex.h:38
friend bool operator>(const gmp_float &a, const gmp_float &b)
gmp_float(const mpf_t v)
Definition mpr_complex.h:46
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition coeffs.h:887
CanonicalForm res
Definition facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
bool operator<(const gmp_complex &a, const gmp_complex &b)
bool operator==(const gmp_complex &a, const gmp_complex &b)
gmp_float max(const gmp_float &, const gmp_float &)
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
gmp_float exp(const gmp_float &)
gmp_float hypot(const gmp_float &, const gmp_float &)
gmp_complex operator/(const gmp_complex &a, const gmp_float b_d)
bool operator>(const gmp_complex &a, const gmp_complex &b)
bool operator<=(const gmp_complex &a, const gmp_complex &b)
gmp_float log(const gmp_float &)
gmp_complex operator+(const gmp_complex &a, const gmp_float b_d)
char * floatToStr(const gmp_float &r, const unsigned int oprec)
bool complexNearZero(gmp_complex *c, int digits)
gmp_complex operator*(const gmp_complex &a, const gmp_float b_d)
gmp_float cos(const gmp_float &)
gmp_float sqrt(const gmp_float &)
gmp_float numberToFloat(number num, const coeffs src)
bool operator>=(const gmp_complex &a, const gmp_complex &b)
gmp_complex numberToComplex(number num, const coeffs r)
gmp_float numberFieldToFloat(number num, int src)
gmp_complex operator-(const gmp_complex &a, const gmp_float b_d)
gmp_float abs(const gmp_float &)
gmp_float sin(const gmp_float &)
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...
double mprfloat
Definition mpr_global.h:17
The main handler for Singular numbers which are suitable for Singular polynomials.