Loading...
Searching...
No Matches
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.

{
Rational
erg;
if (mpq_sgn(a.p->rat)<0)
mpq_neg(erg.p->rat,a.p->rat);
else
mpq_set(erg.p->rat,a.p->rat);
return erg;
}
Rational
Definition GMPrat.h:15
Rational::p
rep * p
Definition GMPrat.h:23
Rational::rep::rat
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.

{
if( a == 0 )
{
if( b == 0 )
{
return (Rational)1;
}
else
{
return abs( b );
}
}
else if( b == 0 )
{
return abs( a );
}
Rational erg;
mpz_gcd( mpq_numref( erg.p->rat ),
mpq_numref( a.p->rat ),mpq_numref( b.p->rat ) );
mpz_gcd( mpq_denref( erg.p->rat ),
mpq_denref( a.p->rat ),mpq_denref( b.p->rat ) );
//mpq_canonicalize( erg.p->rat );
return abs( erg );
}
abs
Rational abs(const Rational &a)
Definition GMPrat.cc:436
b
CanonicalForm b
Definition cfModGcd.cc:4111

## gcd() [2/2]

Rational gcd | ( | Rational * | a,
|  | int | n )

Definition at line 478 of file GMPrat.cc.

{
if( n == 1 )
{
return a[0];
}
Rational g = gcd( a[0],a[1] );
for( int i=2; i<n; i++ )
{
g = gcd( g,a[i] );
}
return g;
}
gcd
Rational gcd(const Rational &a, const Rational &b)
Definition GMPrat.cc:448
i
int i
Definition cfEzgcd.cc:132
g
g
Definition cfModGcd.cc:4098

## lcm() [1/2]

Rational lcm | ( | const Rational & | a,
|  | const Rational & | b )

Definition at line 495 of file GMPrat.cc.

{
if( a == 0 )
{
return b;
}
else if( b == 0 )
{
return a;
}
return a*b/gcd(a,b);
}

## lcm() [2/2]

Rational lcm | ( | Rational * | a,
|  | int | n )

Definition at line 509 of file GMPrat.cc.

{
if( n == 1 )
{
return a[0];
}
Rational g = lcm( a[0],a[1] );
for( int i=2; i<n; i++ )
{
g = lcm( g,a[i] );
}
return g;
}
lcm
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.

{
if (mpq_equal(a.p->rat,b.p->rat)) return false;
return true;
}

## operator*()

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

Definition at line 403 of file GMPrat.cc.

{
Rational
erg(a);
return erg*=b;
}

## operator+()

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

Definition at line 385 of file GMPrat.cc.

{
Rational
erg(a);
return erg+=b;
}

## operator-() [1/2]

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

Definition at line 394 of file GMPrat.cc.

{
Rational
erg(a);
return erg-=b;
}

## operator-() [2/2]

Rational operator- | ( | const Rational & | r | ) |

Definition at line 187 of file GMPrat.cc.

{
Rational erg;
mpq_neg(erg.p->rat,r.p->rat);
return erg;
}

## operator/()

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

Definition at line 422 of file GMPrat.cc.

{
Rational
erg(a);
return erg/=b;
}

## operator<()

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

Definition at line 288 of file GMPrat.cc.

{
if (mpq_cmp(a.p->rat,b.p->rat)<0) return true;
return false;
}

## operator<=()

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

Definition at line 294 of file GMPrat.cc.

{
if (mpq_cmp(a.p->rat,b.p->rat)>0) return false;
return true;
}

## operator==()

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

Definition at line 312 of file GMPrat.cc.

{
if (mpq_equal(a.p->rat,b.p->rat)) return true;
return false;
}

## operator>()

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

Definition at line 300 of file GMPrat.cc.

{
if (mpq_cmp(a.p->rat,b.p->rat)>0) return true;
return false;
}

## operator>=()

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

Definition at line 306 of file GMPrat.cc.

{
if (mpq_cmp(a.p->rat,b.p->rat)<0) return false;
return true;
}

## pow()

Rational pow | ( | const Rational & | a,
|  | int | e )

Definition at line 411 of file GMPrat.cc.

{
Rational erg(1);
for( int i=0; i<e; i++ )
{
erg *= a;
}
return erg;
}

## sgn()

int sgn | ( | const Rational & | a | ) |

Definition at line 430 of file GMPrat.cc.

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