20 #ifndef GMPRAT_IOSTREAM 62 mpq_set_si(
p->
rat,(
long)a,1 );
87 mpq_set_si(
p->
rat,(
long) a,(
unsigned long)
abs(b));
88 mpq_canonicalize(
p->
rat);
116 mpq_set_si(
p->
rat,(
long) a,1);
140 mpq_set_num( erg.
p->
rat,mpq_numref(
p->
rat ) );
147 return mpz_get_si( mpq_numref(
p->
rat ) );
154 mpq_set_num( erg.
p->
rat,mpq_denref(
p->
rat ) );
161 return mpz_get_si( mpq_denref(
p->
rat ) );
168 Rational::operator int()
174 mpz_tdiv_q(h,mpq_numref(
p->
rat),mpq_denref(
p->
rat));
175 ret_val=mpz_get_si(h);
259 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
269 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
277 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
287 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
297 if (mpq_cmp(a.
p->
rat,b.
p->
rat)<0)
return true;
303 if (mpq_cmp(a.
p->
rat,b.
p->
rat)>0)
return false;
309 if (mpq_cmp(a.
p->
rat,b.
p->
rat)>0)
return true;
315 if (mpq_cmp(a.
p->
rat,b.
p->
rat)<0)
return false;
321 if (mpq_equal(a.
p->
rat,b.
p->
rat))
return true;
327 if (mpq_equal(a.
p->
rat,b.
p->
rat))
return false;
340 snum = mpz_get_str(
NULL,10,mpq_numref(a.
p->
rat) );
341 sdenom = mpz_get_str(
NULL,10,mpq_denref(a.
p->
rat) );
343 if( sdenom[0] ==
'1' && sdenom[1] ==
'\0' )
345 #ifdef GMPRAT_IOSTREAM 348 fprintf( stdout,snum );
353 #ifdef GMPRAT_IOSTREAM 354 s << snum <<
"/" << sdenom;
356 fprintf( stdout,snum );
357 fprintf( stdout,
"/" );
358 fprintf( stdout,sdenom );
371 char *snum = (
char*)
NULL;
372 char *sden = (
char*)
NULL;
374 snum = mpz_get_str( snum,10,mpq_numref(
p->
rat ) );
375 sden = mpz_get_str( sden,10,mpq_denref(
p->
rat ) );
377 int length = strlen( snum );
379 if( sden[0] !=
'1' || sden[1] !=
'\0' ) length += strlen( sden ) + 1;
422 for(
int i=0;
i<e;
i++ )
439 return mpq_sgn(a.
p->
rat);
448 if (mpq_sgn(a.
p->
rat)<0)
475 mpz_gcd( mpq_numref( erg.
p->
rat ),
476 mpq_numref( a.
p->
rat ),mpq_numref( b.
p->
rat ) );
477 mpz_gcd( mpq_denref( erg.
p->
rat ),
478 mpq_denref( a.
p->
rat ),mpq_denref( b.
p->
rat ) );
494 for(
int i=2;
i<n;
i++ )
525 for(
int i=2;
i<n;
i++ )
535 double num = mpz_get_d( mpq_numref(
p->
rat ) );
536 double den = mpz_get_d( mpq_denref(
p->
rat ) );
538 if( num < 0 ) num = -
num;
539 if( den < 0 ) den = -
den;
541 return ( num > den ? num : den );
friend Rational lcm(const Rational &, const Rational &)
const CanonicalForm int s
friend bool operator>(const Rational &, const Rational &)
Rational & operator=(int)
friend bool operator>=(const Rational &, const Rational &)
friend bool operator!=(const Rational &, const Rational &)
Rational operator*(const Rational &a, const Rational &b)
friend Rational pow(const Rational &, int)
friend int sgn(const Rational &)
Rational & operator-=(const Rational &)
friend bool operator==(const Rational &, const Rational &)
friend bool operator<(const Rational &, const Rational &)
Rational & operator+=(const Rational &)
unsigned int length() const
Rational & operator/=(const Rational &)
double complexity() const
friend Rational gcd(const Rational &, const Rational &)
Rational & operator*=(const Rational &)
friend Rational abs(const Rational &)
Rational operator/(const Rational &a, const Rational &b)
friend bool operator<=(const Rational &, const Rational &)
ostream & operator<<(ostream &s, const spectrum &spec)
Rational operator+(const Rational &a, const Rational &b)