My Project  UNKNOWN_GIT_VERSION
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() [1/6]

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  }

◆ gmp_float() [2/6]

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  }

◆ gmp_float() [3/6]

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  }

◆ gmp_float() [4/6]

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  }

◆ gmp_float() [5/6]

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  }

◆ gmp_float() [6/6]

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::~gmp_float ( )
inline

Definition at line 60 of file mpr_complex.h.

61  {
62  mpf_clear( t );
63  }

Member Function Documentation

◆ _mpfp()

mpf_t* gmp_float::_mpfp ( )
inline

Definition at line 134 of file mpr_complex.h.

134 { return &t; };

◆ isMOne()

bool gmp_float::isMOne ( ) const

Definition at line 274 of file mpr_complex.cc.

275 {
276 #ifdef VARIANTE_1
277  return (mpf_cmp_si( t , -1 ) == 0);
278 #else
279  if (mpf_sgn(t) >= 0)
280  return false;
281  mpf_add_ui(diff->t, t, 1);
282  mpf_abs(diff->t, diff->t);
283  if(mpf_cmp(diff->t, gmpRel->t) < 0)
284  return true;
285  else
286  return false;
287 #endif
288 }

◆ isOne()

bool gmp_float::isOne ( ) const

Definition at line 258 of file mpr_complex.cc.

259 {
260 #ifdef VARIANTE_1
261  return (mpf_cmp_ui( t , 1 ) == 0);
262 #else
263  if (mpf_sgn(t) <= 0)
264  return false;
265  mpf_sub_ui(diff->t, t, 1);
266  mpf_abs(diff->t, diff->t);
267  if(mpf_cmp(diff->t, gmpRel->t) < 0)
268  return true;
269  else
270  return false;
271 #endif
272 }

◆ isZero()

bool gmp_float::isZero ( ) const

Definition at line 253 of file mpr_complex.cc.

254 {
255  return (mpf_sgn( t ) == 0);
256 }

◆ mpfp()

const mpf_t* gmp_float::mpfp ( ) const
inline

Definition at line 133 of file mpr_complex.h.

133 { return &t; };

◆ neg()

gmp_float& gmp_float::neg ( )
inline

Definition at line 100 of file mpr_complex.h.

100 { mpf_neg(t,t); return *this; };

◆ operator double() [1/2]

gmp_float::operator double ( )
inline

Definition at line 136 of file mpr_complex.h.

136 { return mpf_get_d( t ); };

◆ operator double() [2/2]

gmp_float::operator double ( ) const
inline

Definition at line 137 of file mpr_complex.h.

137 { return mpf_get_d( t ); };

◆ operator*=()

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  };

◆ operator+=()

gmp_float & gmp_float::operator+= ( const gmp_float a)

Definition at line 194 of file mpr_complex.cc.

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

◆ operator-=()

gmp_float & gmp_float::operator-= ( const gmp_float a)

Definition at line 215 of file mpr_complex.cc.

216 {
217  if (mpf_sgn(t) != mpf_sgn(a.t))
218  {
219  mpf_sub( t, t, a.t);
220  return *this;
221  }
222  if((mpf_sgn(a.t)==0) && (mpf_sgn(t)==0))
223  {
224  mpf_set_d( t, 0.0);
225  return *this;
226  }
227  mpf_sub( t, t, a.t );
228  mpf_set(diff->t, t);
229  mpf_set_prec(diff->t, 32);
230  mpf_div(diff->t, diff->t, a.t);
231  mpf_abs(diff->t, diff->t);
232  if(mpf_cmp(diff->t, gmpRel->t) < 0)
233  mpf_set_d( t, 0.0);
234  return *this;
235 }

◆ operator/=()

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  };

◆ operator=() [1/4]

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  };

◆ operator=() [2/4]

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  };

◆ operator=() [3/4]

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  };

◆ operator=() [4/4]

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  };

◆ operator^()

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  };

◆ setFromStr()

void gmp_float::setFromStr ( const char *  in)

Definition at line 79 of file mpr_complex.cc.

80 {
81  BOOLEAN neg=false;
82  if (*in == '-') { in++; neg=TRUE; }
83  char *s;
84  if ((s=strchr((char *)in,'E')) !=NULL)
85  {
86  *s='e';
87  }
88 
89  // gmp doesn't understand number which begin with "." -- it needs 0.
90  // so, insert the zero
91  if (*in == '.')
92  {
93  int len = strlen(in)+2;
94  char* c_in = (char*) omAlloc(len);
95  *c_in = '0';
96  strcpy(&(c_in[1]), in);
97 
98  if(mpf_set_str( t, c_in, 10 )!=0) WerrorS("syntax error in GMP float");
99  omFreeSize((void*)c_in, len);
100  }
101  else
102  {
103  if(mpf_set_str( t, in, 10 )!=0) WerrorS("syntax error in GMP float");
104  }
105  if (neg) mpf_neg( t, t );
106 }

◆ sign()

int gmp_float::sign ( )
inline

Definition at line 123 of file mpr_complex.h.

124  { return mpf_sgn( t ); };

Friends And Related Function Documentation

◆ operator*

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

Definition at line 180 of file mpr_complex.cc.

181 {
182  gmp_float tmp( a );
183  tmp *= b;
184  return tmp;
185 }

◆ operator+

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

Definition at line 168 of file mpr_complex.cc.

169 {
170  gmp_float tmp( a );
171  tmp += b;
172  return tmp;
173 }

◆ operator- [1/2]

gmp_float operator- ( const gmp_float a)
friend

Definition at line 315 of file mpr_complex.cc.

316 {
317  gmp_float tmp;
318  mpf_neg( *(tmp._mpfp()), *(a.mpfp()) );
319  return tmp;
320 }

◆ operator- [2/2]

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

Definition at line 174 of file mpr_complex.cc.

175 {
176  gmp_float tmp( a );
177  tmp -= b;
178  return tmp;
179 }

◆ operator/

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

Definition at line 186 of file mpr_complex.cc.

187 {
188  gmp_float tmp( a );
189  tmp /= b;
190  return tmp;
191 }

◆ operator<

bool operator< ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 295 of file mpr_complex.cc.

296 {
297  if (a.t == b.t)
298  return false;
299  return mpf_cmp( a.t, b.t ) < 0;
300 }

◆ operator<=

bool operator<= ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 307 of file mpr_complex.cc.

308 {
309  if (a.t == b.t)
310  return true;
311  return mpf_cmp( a.t, b.t ) <= 0;
312 }

◆ operator==

bool operator== ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 238 of file mpr_complex.cc.

239 {
240  if(mpf_sgn(a.t) != mpf_sgn(b.t))
241  return false;
242  if((mpf_sgn(a.t)==0) && (mpf_sgn(b.t)==0))
243  return true;
244  mpf_sub(diff->t, a.t, b.t);
245  mpf_div(diff->t, diff->t, a.t);
246  mpf_abs(diff->t, diff->t);
247  if(mpf_cmp(diff->t, gmpRel->t) < 0)
248  return true;
249  else
250  return false;
251 }

◆ operator>

bool operator> ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 289 of file mpr_complex.cc.

290 {
291  if (a.t == b.t)
292  return false;
293  return mpf_cmp( a.t, b.t ) > 0;
294 }

◆ operator>=

bool operator>= ( const gmp_float a,
const gmp_float b 
)
friend

Definition at line 301 of file mpr_complex.cc.

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

Field Documentation

◆ t

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:
diff
static gmp_float * diff
Definition: mpr_complex.cc:46
gmp_float::t
mpf_t t
Definition: mpr_complex.h:137
exp
gmp_float exp(const gmp_float &)
Definition: mpr_complex.cc:358
b
CanonicalForm b
Definition: cfModGcd.cc:4044
gmp_float::_mpfp
mpf_t * _mpfp()
Definition: mpr_complex.h:134
TRUE
#define TRUE
Definition: auxiliary.h:98
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
gmp_float::neg
gmp_float & neg()
Definition: mpr_complex.h:100
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
gmp_float::gmp_float
gmp_float(const int v=0)
Definition: mpr_complex.h:34
gmpRel
static gmp_float * gmpRel
Definition: mpr_complex.cc:45
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
NULL
#define NULL
Definition: omList.c:10
gmp_float::mpfp
const mpf_t * mpfp() const
Definition: mpr_complex.h:133
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
gmp_float
Definition: mpr_complex.h:31