My Project
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | 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
 

Data Fields

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 }
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39

◆ 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 273 of file mpr_complex.cc.

274{
275#ifdef VARIANTE_1
276 return (mpf_cmp_si( t , -1 ) == 0);
277#else
278 if (mpf_sgn(t) >= 0)
279 return false;
280 mpf_add_ui(diff->t, t, 1);
281 mpf_abs(diff->t, diff->t);
282 if(mpf_cmp(diff->t, gmpRel->t) < 0)
283 return true;
284 else
285 return false;
286#endif
287}
STATIC_VAR gmp_float * gmpRel
Definition: mpr_complex.cc:44
STATIC_VAR gmp_float * diff
Definition: mpr_complex.cc:45

◆ isOne()

bool gmp_float::isOne ( ) const

Definition at line 257 of file mpr_complex.cc.

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

◆ isZero()

bool gmp_float::isZero ( ) const

Definition at line 252 of file mpr_complex.cc.

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

◆ 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 193 of file mpr_complex.cc.

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

◆ operator-=()

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

Definition at line 214 of file mpr_complex.cc.

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

◆ 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 };
CanonicalForm b
Definition: cfModGcd.cc:4103
gmp_float exp(const gmp_float &)
Definition: mpr_complex.cc:357

◆ setFromStr()

void gmp_float::setFromStr ( const char *  in)

Definition at line 78 of file mpr_complex.cc.

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

◆ 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 179 of file mpr_complex.cc.

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

◆ operator+

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

Definition at line 167 of file mpr_complex.cc.

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

◆ operator- [1/2]

gmp_float operator- ( const gmp_float a)
friend

Definition at line 314 of file mpr_complex.cc.

315{
316 gmp_float tmp;
317 mpf_neg( *(tmp._mpfp()), *(a.mpfp()) );
318 return tmp;
319}
mpf_t * _mpfp()
Definition: mpr_complex.h:134
const mpf_t * mpfp() const
Definition: mpr_complex.h:133

◆ operator- [2/2]

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

Definition at line 173 of file mpr_complex.cc.

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

◆ operator/

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

Definition at line 185 of file mpr_complex.cc.

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

◆ operator<

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

Definition at line 294 of file mpr_complex.cc.

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

◆ operator<=

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

Definition at line 306 of file mpr_complex.cc.

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

◆ operator==

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

Definition at line 237 of file mpr_complex.cc.

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

◆ operator>

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

Definition at line 288 of file mpr_complex.cc.

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

◆ operator>=

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

Definition at line 300 of file mpr_complex.cc.

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

Field Documentation

◆ t

mpf_t gmp_float::t

Definition at line 151 of file mpr_complex.h.


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