#include <GMPrat.h>
|
Rational | operator- (const Rational &) |
|
bool | operator< (const Rational &, const Rational &) |
|
bool | operator<= (const Rational &, const Rational &) |
|
bool | operator> (const Rational &, const Rational &) |
|
bool | operator>= (const Rational &, const Rational &) |
|
bool | operator== (const Rational &, const Rational &) |
|
bool | operator!= (const Rational &, const Rational &) |
|
int | sgn (const Rational &) |
|
Rational | abs (const Rational &) |
|
Rational | pow (const Rational &, int) |
|
Rational | gcd (const Rational &, const Rational &) |
|
Rational | lcm (const Rational &, const Rational &) |
|
Rational | gcd (Rational *, int) |
|
Rational | lcm (Rational *, int) |
|
Definition at line 14 of file GMPrat.h.
◆ Rational() [1/5]
◆ Rational() [2/5]
Rational::Rational |
( |
int |
a | ) |
|
Definition at line 51 of file GMPrat.cc.
52{
55 mpq_set_si(
p->
rat,(
long)a,1 );
56}
◆ Rational() [3/5]
◆ Rational() [4/5]
◆ Rational() [5/5]
Rational::Rational |
( |
int |
a, |
|
|
int |
b |
|
) |
| |
Definition at line 75 of file GMPrat.cc.
76{
80 mpq_set_si(
p->
rat,(
long) a,(
unsigned long)
abs(
b));
81 mpq_canonicalize(
p->
rat);
82}
friend Rational abs(const Rational &)
◆ ~Rational()
◆ complexity()
double Rational::complexity |
( |
| ) |
const |
Definition at line 526 of file GMPrat.cc.
527{
528 double num = mpz_get_d( mpq_numref(
p->
rat ) );
529 double den = mpz_get_d( mpq_denref(
p->
rat ) );
530
533
535}
◆ disconnect()
void Rational::disconnect |
( |
| ) |
|
|
private |
Definition at line 29 of file GMPrat.cc.
30{
32 {
37 mpq_set(
p->
rat, old_p->rat);
38 }
39}
◆ get_den()
Definition at line 143 of file GMPrat.cc.
144{
146
147 mpq_set_num( erg.
p->
rat,mpq_denref(
p->
rat ) );
148
149 return erg;
150}
◆ get_den_si()
int Rational::get_den_si |
( |
| ) |
|
Definition at line 152 of file GMPrat.cc.
153{
154 return mpz_get_si( mpq_denref(
p->
rat ) );
155}
◆ get_num()
Definition at line 129 of file GMPrat.cc.
130{
132
133 mpq_set_num( erg.
p->
rat,mpq_numref(
p->
rat ) );
134
135 return erg;
136}
◆ get_num_si()
int Rational::get_num_si |
( |
| ) |
|
Definition at line 138 of file GMPrat.cc.
139{
140 return mpz_get_si( mpq_numref(
p->
rat ) );
141}
◆ length()
unsigned int Rational::length |
( |
| ) |
const |
Definition at line 362 of file GMPrat.cc.
363{
364 char *snum = (
char*)
omAlloc(mpz_sizeinbase(mpq_numref(
p->
rat),10)+2);
365 char *sden = (
char*)
omAlloc(mpz_sizeinbase(mpq_denref(
p->
rat),10)+2);
366
367 snum = mpz_get_str( snum,10,mpq_numref(
p->
rat ) );
368 sden = mpz_get_str( sden,10,mpq_denref(
p->
rat ) );
369
370 int length = strlen( snum );
371
372 if( sden[0] !=
'1' || sden[1] !=
'\0' )
length += strlen( sden ) + 1;
373
376
378}
unsigned int length() const
◆ operator int()
Rational::operator int |
( |
| ) |
|
Definition at line 161 of file GMPrat.cc.
162{
164 long ret_val;
165
167 mpz_tdiv_q(
h,mpq_numref(
p->
rat),mpq_denref(
p->
rat));
168 ret_val=mpz_get_si(
h);
170
171 return ret_val;
172}
◆ operator*=()
Definition at line 229 of file GMPrat.cc.
230{
233 return *this;
234}
◆ operator++() [1/2]
Definition at line 249 of file GMPrat.cc.
250{
252 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
253 return *this;
254}
◆ operator++() [2/2]
Definition at line 257 of file GMPrat.cc.
258{
260
262 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
263 return erg;
264}
◆ operator+=()
Definition at line 213 of file GMPrat.cc.
214{
217 return *this;
218}
◆ operator-()
Definition at line 179 of file GMPrat.cc.
180{
182
184 return erg;
185}
◆ operator--() [1/2]
Definition at line 267 of file GMPrat.cc.
268{
270 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
271 return *this;
272}
◆ operator--() [2/2]
Definition at line 275 of file GMPrat.cc.
276{
278
280 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
281 return erg;
282}
◆ operator-=()
Definition at line 221 of file GMPrat.cc.
222{
225 return *this;
226}
◆ operator/=()
Definition at line 237 of file GMPrat.cc.
238{
241 return *this;
242}
◆ operator=() [1/3]
Rational & Rational::operator= |
( |
char * |
s | ) |
|
◆ operator=() [2/3]
Definition at line 113 of file GMPrat.cc.
114{
117 {
120 }
122 return *this;
123}
◆ operator=() [3/3]
Definition at line 101 of file GMPrat.cc.
102{
104 {
108 }
109 mpq_set_si(
p->
rat,(
long) a,1);
110 return *this;
111}
◆ operator~()
Definition at line 200 of file GMPrat.cc.
201{
203
205 return erg;
206}
◆ abs
Definition at line 436 of file GMPrat.cc.
437{
439 erg;
440
441 if (mpq_sgn(a.
p->
rat)<0)
443 else
445 return erg;
446}
◆ gcd [1/2]
Definition at line 448 of file GMPrat.cc.
449{
450 if( a == 0 )
451 {
453 {
455 }
456 else
457 {
459 }
460 }
462 {
464 }
465
467
468 mpz_gcd( mpq_numref( erg.
p->
rat ),
469 mpq_numref( a.
p->
rat ),mpq_numref(
b.p->rat ) );
470 mpz_gcd( mpq_denref( erg.
p->
rat ),
471 mpq_denref( a.
p->
rat ),mpq_denref(
b.p->rat ) );
472
473
474
476}
◆ gcd [2/2]
Definition at line 478 of file GMPrat.cc.
479{
480 if( n == 1 )
481 {
482 return a[0];
483 }
484
486
487 for(
int i=2;
i<n;
i++ )
488 {
490 }
491
493}
friend Rational gcd(const Rational &, const Rational &)
◆ lcm [1/2]
Definition at line 495 of file GMPrat.cc.
496{
497 if( a == 0 )
498 {
500 }
502 {
503 return a;
504 }
505
507}
◆ lcm [2/2]
Definition at line 509 of file GMPrat.cc.
510{
511 if( n == 1 )
512 {
513 return a[0];
514 }
515
517
518 for(
int i=2;
i<n;
i++ )
519 {
521 }
522
524}
friend Rational lcm(const Rational &, const Rational &)
◆ operator!=
Definition at line 318 of file GMPrat.cc.
319{
320 if (mpq_equal(a.
p->
rat,
b.p->rat))
return false;
321 return true;
322}
◆ operator-
Definition at line 187 of file GMPrat.cc.
188{
190
192 return erg;
193}
◆ operator<
Definition at line 288 of file GMPrat.cc.
289{
290 if (mpq_cmp(a.
p->
rat,
b.p->rat)<0)
return true;
291 return false;
292}
◆ operator<=
Definition at line 294 of file GMPrat.cc.
295{
296 if (mpq_cmp(a.
p->
rat,
b.p->rat)>0)
return false;
297 return true;
298}
◆ operator==
Definition at line 312 of file GMPrat.cc.
313{
314 if (mpq_equal(a.
p->
rat,
b.p->rat))
return true;
315 return false;
316}
◆ operator>
Definition at line 300 of file GMPrat.cc.
301{
302 if (mpq_cmp(a.
p->
rat,
b.p->rat)>0)
return true;
303 return false;
304}
◆ operator>=
Definition at line 306 of file GMPrat.cc.
307{
308 if (mpq_cmp(a.
p->
rat,
b.p->rat)<0)
return false;
309 return true;
310}
◆ pow
Definition at line 411 of file GMPrat.cc.
412{
414
415 for(
int i=0;
i<e;
i++ )
416 {
417 erg *= a;
418 }
419 return erg;
420}
◆ sgn
Definition at line 430 of file GMPrat.cc.
431{
432 return mpq_sgn(a.
p->
rat);
433}
The documentation for this class was generated from the following files: