1 | #ifndef MPR_COMPLEX_H |
---|
2 | #define MPR_COMPLEX_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: mpr_complex.h,v 1.3 1999-06-15 16:39:00 Singular Exp $ */ |
---|
7 | |
---|
8 | /* |
---|
9 | * ABSTRACT - multipolynomial resultants - real floating-point numbers using gmp |
---|
10 | * and complex numbers based on pairs of real floating-point numbers |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | //-> include & define stuff |
---|
15 | // must have gmp version >= 2 |
---|
16 | extern "C" { |
---|
17 | #include <gmp.h> |
---|
18 | } |
---|
19 | #include "numbers.h" |
---|
20 | #include "mpr_global.h" |
---|
21 | |
---|
22 | #define DEFPREC 20 // minimum number of digits (output operations) |
---|
23 | |
---|
24 | #define GMP_DEFAULT_PREC_BITS 512 // size of mantissa of floating-point number |
---|
25 | #define GMP_NEEDEQUAL_BITS 512-64 // a == b for the first gmp_equalupto_bits bits |
---|
26 | //<- |
---|
27 | |
---|
28 | void setGMPFloatPrecBytes( unsigned long int bytes ); |
---|
29 | unsigned long int getGMPFloatPrecBytes(); |
---|
30 | void setGMPFloatDigits( size_t digits ); |
---|
31 | size_t getGMPFloatDigits(); |
---|
32 | |
---|
33 | //-> class gmp_float |
---|
34 | /** |
---|
35 | * @short wrapper class for GNU Multi Precision Floats |
---|
36 | */ |
---|
37 | class gmp_float |
---|
38 | { |
---|
39 | public: |
---|
40 | gmp_float( const mprfloat v = 0.0 ); |
---|
41 | gmp_float( const int v ); |
---|
42 | gmp_float( const long v ); |
---|
43 | gmp_float( const mpf_t v ); |
---|
44 | gmp_float( const mpz_t v ); |
---|
45 | gmp_float( const gmp_float & v ); |
---|
46 | |
---|
47 | ~gmp_float(); |
---|
48 | |
---|
49 | friend gmp_float operator + ( const gmp_float & a, const gmp_float & b ); |
---|
50 | friend gmp_float operator - ( const gmp_float & a, const gmp_float & b ); |
---|
51 | friend gmp_float operator * ( const gmp_float & a, const gmp_float & b ); |
---|
52 | friend gmp_float operator / ( const gmp_float & a, const gmp_float & b ); |
---|
53 | |
---|
54 | gmp_float & operator += ( const gmp_float & a ); |
---|
55 | gmp_float & operator -= ( const gmp_float & a ); |
---|
56 | gmp_float & operator *= ( const gmp_float & a ); |
---|
57 | gmp_float & operator /= ( const gmp_float & a ); |
---|
58 | |
---|
59 | friend bool operator == ( const gmp_float & a, const gmp_float & b ); |
---|
60 | friend bool operator > ( const gmp_float & a, const gmp_float & b ); |
---|
61 | friend bool operator < ( const gmp_float & a, const gmp_float & b ); |
---|
62 | friend bool operator >= ( const gmp_float & a, const gmp_float & b ); |
---|
63 | friend bool operator <= ( const gmp_float & a, const gmp_float & b ); |
---|
64 | |
---|
65 | friend gmp_float operator - ( const gmp_float & a ); |
---|
66 | |
---|
67 | gmp_float & operator = ( const gmp_float & a ); |
---|
68 | gmp_float & operator = ( const mpz_t & a ); |
---|
69 | gmp_float & operator = ( const mprfloat a ); |
---|
70 | gmp_float & operator = ( const long a ); |
---|
71 | |
---|
72 | int sign(); // t>0:+1, t==0:0, t<0:-1 |
---|
73 | bool isZero(); // t == 0 ? |
---|
74 | bool isOne(); // t == 1 ? |
---|
75 | bool isMOne(); // t == -1 ? |
---|
76 | |
---|
77 | bool setFromStr( char * in ); |
---|
78 | |
---|
79 | // access |
---|
80 | inline const mpf_t *mpfp() const; |
---|
81 | |
---|
82 | operator double(); |
---|
83 | operator double() const; |
---|
84 | |
---|
85 | operator int(); |
---|
86 | operator int() const; |
---|
87 | |
---|
88 | public: |
---|
89 | static void setPrecision( const unsigned long int prec ) |
---|
90 | { gmp_default_prec_bits= prec; } |
---|
91 | static void setEqualBits( const unsigned long int prec ) |
---|
92 | { gmp_needequal_bits= prec; } |
---|
93 | |
---|
94 | static const unsigned long int getPrecision() |
---|
95 | { return gmp_default_prec_bits; } |
---|
96 | static const unsigned long int getEqualBits() |
---|
97 | { return gmp_needequal_bits; } |
---|
98 | |
---|
99 | private: |
---|
100 | static unsigned long int gmp_default_prec_bits; |
---|
101 | static unsigned long int gmp_needequal_bits; |
---|
102 | |
---|
103 | mpf_t t; |
---|
104 | }; |
---|
105 | |
---|
106 | // built-in functions of GMP |
---|
107 | gmp_float abs( const gmp_float & ); |
---|
108 | gmp_float sqrt( const gmp_float & ); |
---|
109 | gmp_float hypot( const gmp_float &, const gmp_float & ); |
---|
110 | |
---|
111 | // simulated functions using double functions |
---|
112 | gmp_float sin( const gmp_float & ); |
---|
113 | gmp_float cos( const gmp_float & ); |
---|
114 | gmp_float log( const gmp_float & ); |
---|
115 | gmp_float exp( const gmp_float & ); |
---|
116 | |
---|
117 | gmp_float max( const gmp_float &, const gmp_float & ); |
---|
118 | |
---|
119 | gmp_float numberToFloat( number num ); |
---|
120 | char *floatToStr( const gmp_float & r, const size_t oprec ); |
---|
121 | |
---|
122 | typedef gmp_float mprfloat_g; |
---|
123 | //<- |
---|
124 | |
---|
125 | //-> class complex |
---|
126 | /** |
---|
127 | * @short complex numbers based on |
---|
128 | */ |
---|
129 | class complex |
---|
130 | { |
---|
131 | private: |
---|
132 | mprfloat_g r, i; |
---|
133 | |
---|
134 | public: |
---|
135 | complex( const mprfloat_g re= 0.0, const mprfloat_g im= 0.0 ); |
---|
136 | complex( const mprfloat re, const mprfloat im = 0.0 ); |
---|
137 | complex( const long re, const long im ); |
---|
138 | complex( const complex & v ); |
---|
139 | |
---|
140 | ~complex(); |
---|
141 | |
---|
142 | friend complex operator + ( const complex & a, const complex & b ); |
---|
143 | friend complex operator - ( const complex & a, const complex & b ); |
---|
144 | friend complex operator * ( const complex & a, const complex & b ); |
---|
145 | friend complex operator / ( const complex & a, const complex & b ); |
---|
146 | |
---|
147 | friend complex operator + ( const complex & a, const mprfloat_g b_d ); |
---|
148 | friend complex operator - ( const complex & a, const mprfloat_g b_d ); |
---|
149 | friend complex operator * ( const complex & a, const mprfloat_g b_d ); |
---|
150 | friend complex operator / ( const complex & a, const mprfloat_g b_d ); |
---|
151 | |
---|
152 | complex & operator += ( const complex & a ); |
---|
153 | complex & operator -= ( const complex & a ); |
---|
154 | complex & operator *= ( const complex & a ); |
---|
155 | complex & operator /= ( const complex & a ); |
---|
156 | |
---|
157 | friend bool operator == ( const complex & a, const complex & b ); |
---|
158 | |
---|
159 | complex & operator = ( const complex & a ); |
---|
160 | |
---|
161 | // access to real and imaginary part |
---|
162 | inline mprfloat_g real() const { return r; } |
---|
163 | inline mprfloat_g imag() const { return i; } |
---|
164 | |
---|
165 | inline void real( mprfloat_g val ) { r = val; } |
---|
166 | inline void imag( mprfloat_g val ) { i = val; } |
---|
167 | }; |
---|
168 | |
---|
169 | mprfloat_g abs( const complex & c ); |
---|
170 | complex sqrt( const complex & x ); |
---|
171 | |
---|
172 | inline complex numberToComplex( number num ) |
---|
173 | { |
---|
174 | return complex( numberToFloat(num) ); |
---|
175 | } |
---|
176 | char *complexToStr( const complex & c, const size_t oprec ); |
---|
177 | //<- |
---|
178 | |
---|
179 | #endif MPR_COMPLEX_H |
---|
180 | |
---|
181 | // local Variables: *** |
---|
182 | // folded-file: t *** |
---|
183 | // compile-command-1: "make installg" *** |
---|
184 | // compile-command-2: "make install" *** |
---|
185 | // End: *** |
---|