My Project  UNKNOWN_GIT_VERSION
Macros | Functions
GMPrat.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "kernel/spectrum/GMPrat.h"

Go to the source code of this file.

Macros

#define GMPRAT_CC
 

Functions

Rational operator- (const Rational &r)
 
bool operator< (const Rational &a, const Rational &b)
 
bool operator<= (const Rational &a, const Rational &b)
 
bool operator> (const Rational &a, const Rational &b)
 
bool operator>= (const Rational &a, const Rational &b)
 
bool operator== (const Rational &a, const Rational &b)
 
bool operator!= (const Rational &a, const Rational &b)
 
Rational operator+ (const Rational &a, const Rational &b)
 
Rational operator- (const Rational &a, const Rational &b)
 
Rational operator* (const Rational &a, const Rational &b)
 
Rational pow (const Rational &a, int e)
 
Rational operator/ (const Rational &a, const Rational &b)
 
int sgn (const Rational &a)
 
Rational abs (const Rational &a)
 
Rational gcd (const Rational &a, const Rational &b)
 
Rational gcd (Rational *a, int n)
 
Rational lcm (const Rational &a, const Rational &b)
 
Rational lcm (Rational *a, int n)
 

Macro Definition Documentation

◆ GMPRAT_CC

#define GMPRAT_CC

Definition at line 9 of file GMPrat.cc.

Function Documentation

◆ abs()

Rational abs ( const Rational a)

Definition at line 439 of file GMPrat.cc.

440 {
441  Rational
442  erg;
443 
444  if (mpq_sgn(a.p->rat)<0)
445  mpq_neg(erg.p->rat,a.p->rat);
446  else
447  mpq_set(erg.p->rat,a.p->rat);
448  return erg;
449 }
mpq_t rat
Definition: GMPrat.h:18
rep * p
Definition: GMPrat.h:23

◆ gcd() [1/2]

Rational gcd ( const Rational a,
const Rational b 
)

Definition at line 451 of file GMPrat.cc.

452 {
453  if( a == 0 )
454  {
455  if( b == 0 )
456  {
457  return (Rational)1;
458  }
459  else
460  {
461  return abs( b );
462  }
463  }
464  else if( b == 0 )
465  {
466  return abs( a );
467  }
468 
469  Rational erg;
470 
471  mpz_gcd( mpq_numref( erg.p->rat ),
472  mpq_numref( a.p->rat ),mpq_numref( b.p->rat ) );
473  mpz_gcd( mpq_denref( erg.p->rat ),
474  mpq_denref( a.p->rat ),mpq_denref( b.p->rat ) );
475 
476  //mpq_canonicalize( erg.p->rat );
477 
478  return abs( erg );
479 }
mpq_t rat
Definition: GMPrat.h:18
Rational abs(const Rational &a)
Definition: GMPrat.cc:439
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ gcd() [2/2]

Rational gcd ( Rational a,
int  n 
)

Definition at line 481 of file GMPrat.cc.

482 {
483  if( n == 1 )
484  {
485  return a[0];
486  }
487 
488  Rational g = gcd( a[0],a[1] );
489 
490  for( int i=2; i<n; i++ )
491  {
492  g = gcd( g,a[i] );
493  }
494 
495  return g;
496 }
g
Definition: cfModGcd.cc:4031
Rational gcd(const Rational &a, const Rational &b)
Definition: GMPrat.cc:451
int i
Definition: cfEzgcd.cc:125

◆ lcm() [1/2]

Rational lcm ( const Rational a,
const Rational b 
)

Definition at line 498 of file GMPrat.cc.

499 {
500  if( a == 0 )
501  {
502  return b;
503  }
504  else if( b == 0 )
505  {
506  return a;
507  }
508 
509  return a*b/gcd(a,b);
510 }
Rational gcd(const Rational &a, const Rational &b)
Definition: GMPrat.cc:451
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ lcm() [2/2]

Rational lcm ( Rational a,
int  n 
)

Definition at line 512 of file GMPrat.cc.

513 {
514  if( n == 1 )
515  {
516  return a[0];
517  }
518 
519  Rational g = lcm( a[0],a[1] );
520 
521  for( int i=2; i<n; i++ )
522  {
523  g = lcm( g,a[i] );
524  }
525 
526  return g;
527 }
g
Definition: cfModGcd.cc:4031
int i
Definition: cfEzgcd.cc:125
Rational lcm(const Rational &a, const Rational &b)
Definition: GMPrat.cc:498

◆ operator!=()

bool operator!= ( const Rational a,
const Rational b 
)

Definition at line 321 of file GMPrat.cc.

322 {
323  if (mpq_equal(a.p->rat,b.p->rat)) return false;
324  return true;
325 }
mpq_t rat
Definition: GMPrat.h:18
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ operator*()

Rational operator* ( const Rational a,
const Rational b 
)

Definition at line 406 of file GMPrat.cc.

407 {
408  Rational
409  erg(a);
410 
411  return erg*=b;
412 }
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ operator+()

Rational operator+ ( const Rational a,
const Rational b 
)

Definition at line 388 of file GMPrat.cc.

389 {
390  Rational
391  erg(a);
392 
393  return erg+=b;
394 }
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ operator-() [1/2]

Rational operator- ( const Rational r)

Definition at line 190 of file GMPrat.cc.

191 {
192  Rational erg;
193 
194  mpq_neg(erg.p->rat,r.p->rat);
195  return erg;
196 }
mpq_t rat
Definition: GMPrat.h:18
rep * p
Definition: GMPrat.h:23

◆ operator-() [2/2]

Rational operator- ( const Rational a,
const Rational b 
)

Definition at line 397 of file GMPrat.cc.

398 {
399  Rational
400  erg(a);
401 
402  return erg-=b;
403 }
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ operator/()

Rational operator/ ( const Rational a,
const Rational b 
)

Definition at line 425 of file GMPrat.cc.

426 {
427  Rational
428  erg(a);
429 
430  return erg/=b;
431 }
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ operator<()

bool operator< ( const Rational a,
const Rational b 
)

Definition at line 291 of file GMPrat.cc.

292 {
293  if (mpq_cmp(a.p->rat,b.p->rat)<0) return true;
294  return false;
295 }
mpq_t rat
Definition: GMPrat.h:18
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ operator<=()

bool operator<= ( const Rational a,
const Rational b 
)

Definition at line 297 of file GMPrat.cc.

298 {
299  if (mpq_cmp(a.p->rat,b.p->rat)>0) return false;
300  return true;
301 }
mpq_t rat
Definition: GMPrat.h:18
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ operator==()

bool operator== ( const Rational a,
const Rational b 
)

Definition at line 315 of file GMPrat.cc.

316 {
317  if (mpq_equal(a.p->rat,b.p->rat)) return true;
318  return false;
319 }
mpq_t rat
Definition: GMPrat.h:18
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ operator>()

bool operator> ( const Rational a,
const Rational b 
)

Definition at line 303 of file GMPrat.cc.

304 {
305  if (mpq_cmp(a.p->rat,b.p->rat)>0) return true;
306  return false;
307 }
mpq_t rat
Definition: GMPrat.h:18
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ operator>=()

bool operator>= ( const Rational a,
const Rational b 
)

Definition at line 309 of file GMPrat.cc.

310 {
311  if (mpq_cmp(a.p->rat,b.p->rat)<0) return false;
312  return true;
313 }
mpq_t rat
Definition: GMPrat.h:18
CanonicalForm b
Definition: cfModGcd.cc:4044
rep * p
Definition: GMPrat.h:23

◆ pow()

Rational pow ( const Rational a,
int  e 
)

Definition at line 414 of file GMPrat.cc.

415 {
416  Rational erg(1);
417 
418  for( int i=0; i<e; i++ )
419  {
420  erg *= a;
421  }
422  return erg;
423 }
int i
Definition: cfEzgcd.cc:125

◆ sgn()

int sgn ( const Rational a)

Definition at line 433 of file GMPrat.cc.

434 {
435  return mpq_sgn(a.p->rat);
436 }
mpq_t rat
Definition: GMPrat.h:18
rep * p
Definition: GMPrat.h:23