My Project
Loading...
Searching...
No Matches
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 436 of file GMPrat.cc.

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

◆ gcd() [1/2]

Rational gcd ( const Rational a,
const Rational b 
)

Definition at line 448 of file GMPrat.cc.

449{
450 if( a == 0 )
451 {
452 if( b == 0 )
453 {
454 return (Rational)1;
455 }
456 else
457 {
458 return abs( b );
459 }
460 }
461 else if( b == 0 )
462 {
463 return abs( a );
464 }
465
466 Rational erg;
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 //mpq_canonicalize( erg.p->rat );
474
475 return abs( erg );
476}
Rational abs(const Rational &a)
Definition: GMPrat.cc:436
CanonicalForm b
Definition: cfModGcd.cc:4103

◆ gcd() [2/2]

Rational gcd ( Rational a,
int  n 
)

Definition at line 478 of file GMPrat.cc.

479{
480 if( n == 1 )
481 {
482 return a[0];
483 }
484
485 Rational g = gcd( a[0],a[1] );
486
487 for( int i=2; i<n; i++ )
488 {
489 g = gcd( g,a[i] );
490 }
491
492 return g;
493}
Rational gcd(const Rational &a, const Rational &b)
Definition: GMPrat.cc:448
int i
Definition: cfEzgcd.cc:132
g
Definition: cfModGcd.cc:4090

◆ lcm() [1/2]

Rational lcm ( const Rational a,
const Rational b 
)

Definition at line 495 of file GMPrat.cc.

496{
497 if( a == 0 )
498 {
499 return b;
500 }
501 else if( b == 0 )
502 {
503 return a;
504 }
505
506 return a*b/gcd(a,b);
507}

◆ lcm() [2/2]

Rational lcm ( Rational a,
int  n 
)

Definition at line 509 of file GMPrat.cc.

510{
511 if( n == 1 )
512 {
513 return a[0];
514 }
515
516 Rational g = lcm( a[0],a[1] );
517
518 for( int i=2; i<n; i++ )
519 {
520 g = lcm( g,a[i] );
521 }
522
523 return g;
524}
Rational lcm(const Rational &a, const Rational &b)
Definition: GMPrat.cc:495

◆ operator!=()

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

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*()

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

Definition at line 403 of file GMPrat.cc.

404{
406 erg(a);
407
408 return erg*=b;
409}

◆ operator+()

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

Definition at line 385 of file GMPrat.cc.

386{
388 erg(a);
389
390 return erg+=b;
391}

◆ operator-() [1/2]

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

Definition at line 394 of file GMPrat.cc.

395{
397 erg(a);
398
399 return erg-=b;
400}

◆ operator-() [2/2]

Rational operator- ( const Rational r)

Definition at line 187 of file GMPrat.cc.

188{
189 Rational erg;
190
191 mpq_neg(erg.p->rat,r.p->rat);
192 return erg;
193}

◆ operator/()

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

Definition at line 422 of file GMPrat.cc.

423{
425 erg(a);
426
427 return erg/=b;
428}

◆ operator<()

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

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<=()

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

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==()

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

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>()

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

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>=()

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

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()

Rational pow ( const Rational a,
int  e 
)

Definition at line 411 of file GMPrat.cc.

412{
413 Rational erg(1);
414
415 for( int i=0; i<e; i++ )
416 {
417 erg *= a;
418 }
419 return erg;
420}

◆ sgn()

int sgn ( const Rational a)

Definition at line 430 of file GMPrat.cc.

431{
432 return mpq_sgn(a.p->rat);
433}