17#ifndef GMPRAT_IOSTREAM
55 mpq_set_si(
p->
rat,(
long)a,1 );
80 mpq_set_si(
p->
rat,(
long) a,(
unsigned long)
abs(
b));
81 mpq_canonicalize(
p->
rat);
109 mpq_set_si(
p->
rat,(
long) a,1);
133 mpq_set_num( erg.
p->
rat,mpq_numref(
p->
rat ) );
140 return mpz_get_si( mpq_numref(
p->
rat ) );
147 mpq_set_num( erg.
p->
rat,mpq_denref(
p->
rat ) );
154 return mpz_get_si( mpq_denref(
p->
rat ) );
161Rational::operator int()
167 mpz_tdiv_q(
h,mpq_numref(
p->rat),mpq_denref(
p->rat));
168 ret_val=mpz_get_si(
h);
252 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
262 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
270 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
280 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
290 if (mpq_cmp(a.
p->
rat,
b.p->rat)<0)
return true;
296 if (mpq_cmp(a.
p->
rat,
b.p->rat)>0)
return false;
302 if (mpq_cmp(a.
p->
rat,
b.p->rat)>0)
return true;
308 if (mpq_cmp(a.
p->
rat,
b.p->rat)<0)
return false;
314 if (mpq_equal(a.
p->
rat,
b.p->rat))
return true;
320 if (mpq_equal(a.
p->
rat,
b.p->rat))
return false;
333 snum = mpz_get_str(
NULL,10,mpq_numref(a.
p->
rat) );
334 sdenom = mpz_get_str(
NULL,10,mpq_denref(a.
p->
rat) );
336 if( sdenom[0] ==
'1' && sdenom[1] ==
'\0' )
338 #ifdef GMPRAT_IOSTREAM
341 fprintf( stdout,snum );
346 #ifdef GMPRAT_IOSTREAM
347 s << snum <<
"/" << sdenom;
349 fprintf( stdout,snum );
350 fprintf( stdout,
"/" );
351 fprintf( stdout,sdenom );
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);
367 snum = mpz_get_str( snum,10,mpq_numref(
p->
rat ) );
368 sden = mpz_get_str( sden,10,mpq_denref(
p->
rat ) );
370 int length = strlen( snum );
372 if( sden[0] !=
'1' || sden[1] !=
'\0' )
length += strlen( sden ) + 1;
415 for(
int i=0;
i<e;
i++ )
432 return mpq_sgn(a.
p->
rat);
441 if (mpq_sgn(a.
p->
rat)<0)
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 ) );
487 for(
int i=2;
i<n;
i++ )
518 for(
int i=2;
i<n;
i++ )
528 double num = mpz_get_d( mpq_numref(
p->
rat ) );
529 double den = mpz_get_d( mpq_denref(
p->
rat ) );
bool operator!=(const Rational &a, const Rational &b)
Rational lcm(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 pow(const Rational &a, int e)
bool operator==(const Rational &a, const Rational &b)
Rational operator/(const Rational &a, const Rational &b)
int sgn(const Rational &a)
Rational abs(const Rational &a)
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)
Rational gcd(const Rational &a, const Rational &b)
Rational & operator*=(const Rational &)
friend Rational abs(const Rational &)
Rational & operator-=(const Rational &)
double complexity() const
unsigned int length() const
Rational & operator+=(const Rational &)
Rational & operator=(int)
Rational & operator/=(const Rational &)
const CanonicalForm int s
ostream & operator<<(ostream &s, const spectrum &spec)