Public Member Functions | Private Attributes | Friends
gmp_float Class Reference

#include <mpr_complex.h>

Public Member Functions

 gmp_float (const int v=0)
 
 gmp_float (const long v)
 
 gmp_float (const mprfloat v)
 
 gmp_float (const mpf_t v)
 
 gmp_float (const mpz_t v)
 
 gmp_float (const gmp_float &v)
 
 ~gmp_float ()
 
gmp_floatoperator= (const gmp_float &a)
 
gmp_floatoperator= (const mpz_t &a)
 
gmp_floatoperator= (const mprfloat a)
 
gmp_floatoperator= (const long a)
 
gmp_floatoperator+= (const gmp_float &a)
 
gmp_floatoperator-= (const gmp_float &a)
 
gmp_floatoperator*= (const gmp_float &a)
 
gmp_floatoperator/= (const gmp_float &a)
 
gmp_floatneg ()
 
gmp_float operator^ (const int exp) const
 
int sign ()
 
bool isZero () const
 
bool isOne () const
 
bool isMOne () const
 
void setFromStr (const char *in)
 
const mpf_t * mpfp () const
 
mpf_t * _mpfp ()
 
 operator double ()
 
 operator double () const
 

Private Attributes

mpf_t t
 

Friends

gmp_float operator+ (const gmp_float &a, const gmp_float &b)
 
gmp_float operator- (const gmp_float &a, const gmp_float &b)
 
gmp_float operator* (const gmp_float &a, const gmp_float &b)
 
gmp_float operator/ (const gmp_float &a, const gmp_float &b)
 
bool operator== (const gmp_float &a, const gmp_float &b)
 
bool operator> (const gmp_float &a, const gmp_float &b)
 
bool operator< (const gmp_float &a, const gmp_float &b)
 
bool operator>= (const gmp_float &a, const gmp_float &b)
 
bool operator<= (const gmp_float &a, const gmp_float &b)
 
gmp_float operator- (const gmp_float &a)
 

Detailed Description

Definition at line 31 of file mpr_complex.h.

Constructor & Destructor Documentation

gmp_float::gmp_float ( const int  v = 0)
inline

Definition at line 34 of file mpr_complex.h.

35  {
36  mpf_init_set_si( t, (long)v );
37  }
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
gmp_float::gmp_float ( const long  v)
inline

Definition at line 38 of file mpr_complex.h.

39  {
40  mpf_init_set_si( t, v );
41  }
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
gmp_float::gmp_float ( const mprfloat  v)
inline

Definition at line 42 of file mpr_complex.h.

43  {
44  mpf_init_set_d( t, v );
45  }
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
gmp_float::gmp_float ( const mpf_t  v)
inline

Definition at line 46 of file mpr_complex.h.

47  {
48  mpf_init_set( t, v );
49  }
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
gmp_float::gmp_float ( const mpz_t  v)
inline

Definition at line 50 of file mpr_complex.h.

51  {
52  mpf_init( t );
53  mpf_set_z( t, v );
54  }
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
gmp_float::gmp_float ( const gmp_float v)
inline

Definition at line 55 of file mpr_complex.h.

56  {
57  mpf_init_set( t, v.t );
58  }
gmp_float::~gmp_float ( )
inline

Definition at line 60 of file mpr_complex.h.

61  {
62  mpf_clear( t );
63  }

Member Function Documentation

mpf_t* gmp_float::_mpfp ( )
inline

Definition at line 134 of file mpr_complex.h.

134 { return &t; };
bool gmp_float::isMOne ( ) const

Definition at line 275 of file mpr_complex.cc.

276 {
277 #ifdef VARIANTE_1
278  return (mpf_cmp_si( t , -1 ) == 0);
279 #else
280  if (mpf_sgn(t) >= 0)
281  return false;
282  mpf_add_ui(diff->t, t, 1);
283  mpf_abs(diff->t, diff->t);
284  if(mpf_cmp(diff->t, gmpRel->t) < 0)
285  return true;
286  else
287  return false;
288 #endif
289 }
static gmp_float * diff
Definition: mpr_complex.cc:47
static gmp_float * gmpRel
Definition: mpr_complex.cc:46
bool gmp_float::isOne ( ) const

Definition at line 259 of file mpr_complex.cc.

260 {
261 #ifdef VARIANTE_1
262  return (mpf_cmp_ui( t , 1 ) == 0);
263 #else
264  if (mpf_sgn(t) <= 0)
265  return false;
266  mpf_sub_ui(diff->t, t, 1);
267  mpf_abs(diff->t, diff->t);
268  if(mpf_cmp(diff->t, gmpRel->t) < 0)
269  return true;
270  else
271  return false;
272 #endif
273 }
static gmp_float * diff
Definition: mpr_complex.cc:47
static gmp_float * gmpRel
Definition: mpr_complex.cc:46
bool gmp_float::isZero ( ) const

Definition at line 254 of file mpr_complex.cc.

255 {
256  return (mpf_sgn( t ) == 0);
257 }
const mpf_t* gmp_float::mpfp ( ) const
inline

Definition at line 133 of file mpr_complex.h.

133 { return &t; };
gmp_float& gmp_float::neg ( )
inline

Definition at line 100 of file mpr_complex.h.

100 { mpf_neg(t,t); return *this; };
gmp_float::operator double ( )
inline

Definition at line 136 of file mpr_complex.h.

136 { return mpf_get_d( t ); };
gmp_float::operator double ( ) const
inline

Definition at line 137 of file mpr_complex.h.

137 { return mpf_get_d( t ); };
gmp_float& gmp_float::operator*= ( const gmp_float a)
inline

Definition at line 88 of file mpr_complex.h.

89  {
90  mpf_mul( t, t, a.t );
91  return *this;
92  };
gmp_float & gmp_float::operator+= ( const gmp_float a)

Definition at line 195 of file mpr_complex.cc.

196 {
197  if (mpf_sgn(t) != -(mpf_sgn(a.t)))
198  {
199  mpf_add( t, t, a.t);
200  return *this;
201  }
202  if((mpf_sgn(a.t)==0) && (mpf_sgn(t)==0))
203  {
204  mpf_set_d( t, 0.0);
205  return *this;
206  }
207  mpf_add( t, t, a.t );
208  mpf_set(diff->t, t);
209  mpf_set_prec(diff->t, 32);
210  mpf_div(diff->t, diff->t, a.t);
211  mpf_abs(diff->t, diff->t);
212  if(mpf_cmp(diff->t, gmpRel->t) < 0)
213  mpf_set_d( t, 0.0);
214  return *this;
215 }
static gmp_float * diff
Definition: mpr_complex.cc:47
static gmp_float * gmpRel
Definition: mpr_complex.cc:46
gmp_float & gmp_float::operator-= ( const gmp_float a)

Definition at line 216 of file mpr_complex.cc.

217 {
218  if (mpf_sgn(t) != mpf_sgn(a.t))
219  {
220  mpf_sub( t, t, a.t);
221  return *this;
222  }
223  if((mpf_sgn(a.t)==0) && (mpf_sgn(t)==0))
224  {
225  mpf_set_d( t, 0.0);
226  return *this;
227  }
228  mpf_sub( t, t, a.t );
229  mpf_set(diff->t, t);
230  mpf_set_prec(diff->t, 32);
231  mpf_div(diff->t, diff->t, a.t);
232  mpf_abs(diff->t, diff->t);
233  if(mpf_cmp(diff->t, gmpRel->t) < 0)
234  mpf_set_d( t, 0.0);
235  return *this;
236 }
static gmp_float * diff
Definition: mpr_complex.cc:47
static gmp_float * gmpRel
Definition: mpr_complex.cc:46
gmp_float& gmp_float::operator/= ( const gmp_float a)
inline

Definition at line 94 of file mpr_complex.h.

95  {
96  mpf_div( t, t, a.t );
97  return *this;
98  };
gmp_float& gmp_float::operator= ( const gmp_float a)
inline

Definition at line 65 of file mpr_complex.h.

66  {
67  mpf_set( t, a.t );
68  return *this;
69  };
gmp_float& gmp_float::operator= ( const mpz_t &  a)
inline

Definition at line 70 of file mpr_complex.h.

71  {
72  mpf_set_z( t, a );
73  return *this;
74  };
const poly a
Definition: syzextra.cc:212
gmp_float& gmp_float::operator= ( const mprfloat  a)
inline

Definition at line 75 of file mpr_complex.h.

76  {
77  mpf_set_d( t, (double) a );
78  return *this;
79  };
const poly a
Definition: syzextra.cc:212
gmp_float& gmp_float::operator= ( const long  a)
inline

Definition at line 80 of file mpr_complex.h.

81  {
82  mpf_set_d( t, (double) a );
83  return *this;
84  };
const poly a
Definition: syzextra.cc:212
gmp_float gmp_float::operator^ ( const int  exp) const
inline

Definition at line 107 of file mpr_complex.h.

108  {
109  mpf_t b;
110  mpf_init(b);
111  mpf_pow_ui( b, this->t, (unsigned long)exp );
112  return gmp_float(b);
113  };
gmp_float exp(const gmp_float &)
Definition: mpr_complex.cc:359
gmp_float(const int v=0)
Definition: mpr_complex.h:34
const poly b
Definition: syzextra.cc:213
void gmp_float::setFromStr ( const char *  in)

Definition at line 80 of file mpr_complex.cc.

81 {
82  BOOLEAN neg=false;
83  if (*in == '-') { in++; neg=TRUE; }
84  char *s;
85  if ((s=strchr((char *)in,'E')) !=NULL)
86  {
87  *s='e';
88  }
89 
90  // gmp doesn't understand number which begin with "." -- it needs 0.
91  // so, insert the zero
92  if (*in == '.')
93  {
94  int len = strlen(in)+2;
95  char* c_in = (char*) omAlloc(len);
96  *c_in = '0';
97  strcpy(&(c_in[1]), in);
98 
99  if(mpf_set_str( t, c_in, 10 )!=0) WerrorS("syntax error in GMP float");
100  omFreeSize((void*)c_in, len);
101  }
102  else
103  {
104  if(mpf_set_str( t, in, 10 )!=0) WerrorS("syntax error in GMP float");
105  }
106  if (neg) mpf_neg( t, t );
107 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
gmp_float & neg()
Definition: mpr_complex.h:100
#define TRUE
Definition: auxiliary.h:144
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
int gmp_float::sign ( )
inline

Definition at line 123 of file mpr_complex.h.

124  { return mpf_sgn( t ); };

Friends And Related Function Documentation

gmp_float operator* ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 181 of file mpr_complex.cc.

182 {
183  gmp_float tmp( a );
184  tmp *= b;
185  return tmp;
186 }
const poly b
Definition: syzextra.cc:213
gmp_float operator+ ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 169 of file mpr_complex.cc.

170 {
171  gmp_float tmp( a );
172  tmp += b;
173  return tmp;
174 }
const poly b
Definition: syzextra.cc:213
gmp_float operator- ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 175 of file mpr_complex.cc.

176 {
177  gmp_float tmp( a );
178  tmp -= b;
179  return tmp;
180 }
const poly b
Definition: syzextra.cc:213
gmp_float operator- ( const gmp_float a)
friend

Definition at line 316 of file mpr_complex.cc.

317 {
318  gmp_float tmp;
319  mpf_neg( *(tmp._mpfp()), *(a.mpfp()) );
320  return tmp;
321 }
const mpf_t * mpfp() const
Definition: mpr_complex.h:133
mpf_t * _mpfp()
Definition: mpr_complex.h:134
gmp_float operator/ ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 187 of file mpr_complex.cc.

188 {
189  gmp_float tmp( a );
190  tmp /= b;
191  return tmp;
192 }
const poly b
Definition: syzextra.cc:213
bool operator< ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 296 of file mpr_complex.cc.

297 {
298  if (a.t == b.t)
299  return false;
300  return mpf_cmp( a.t, b.t ) < 0;
301 }
bool operator<= ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 308 of file mpr_complex.cc.

309 {
310  if (a.t == b.t)
311  return true;
312  return mpf_cmp( a.t, b.t ) <= 0;
313 }
bool operator== ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 239 of file mpr_complex.cc.

240 {
241  if(mpf_sgn(a.t) != mpf_sgn(b.t))
242  return false;
243  if((mpf_sgn(a.t)==0) && (mpf_sgn(b.t)==0))
244  return true;
245  mpf_sub(diff->t, a.t, b.t);
246  mpf_div(diff->t, diff->t, a.t);
247  mpf_abs(diff->t, diff->t);
248  if(mpf_cmp(diff->t, gmpRel->t) < 0)
249  return true;
250  else
251  return false;
252 }
static gmp_float * diff
Definition: mpr_complex.cc:47
static gmp_float * gmpRel
Definition: mpr_complex.cc:46
bool operator> ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 290 of file mpr_complex.cc.

291 {
292  if (a.t == b.t)
293  return false;
294  return mpf_cmp( a.t, b.t ) > 0;
295 }
bool operator>= ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 302 of file mpr_complex.cc.

303 {
304  if (a.t == b.t)
305  return true;
306  return mpf_cmp( a.t, b.t ) >= 0;
307 }

Field Documentation

mpf_t gmp_float::t
private

Definition at line 137 of file mpr_complex.h.


The documentation for this class was generated from the following files: