20 #ifndef GMPRAT_IOSTREAM 58 mpq_set_si(
p->
rat,(
long)a,1 );
83 mpq_set_si(
p->
rat,(
long) a,(
unsigned long)
abs(b));
84 mpq_canonicalize(
p->
rat);
112 mpq_set_si(
p->
rat,(
long) a,1);
136 mpq_set_num( erg.
p->
rat,mpq_numref(
p->
rat ) );
143 return mpz_get_si( mpq_numref(
p->
rat ) );
150 mpq_set_num( erg.
p->
rat,mpq_denref(
p->
rat ) );
157 return mpz_get_si( mpq_denref(
p->
rat ) );
164 Rational::operator int()
170 mpz_tdiv_q(h,mpq_numref(
p->
rat),mpq_denref(
p->
rat));
171 ret_val=mpz_get_si(h);
255 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
265 mpz_add(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
273 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
283 mpz_sub(mpq_numref(
p->
rat), mpq_numref(
p->
rat), mpq_denref(
p->
rat));
293 if (mpq_cmp(a.
p->
rat,b.
p->
rat)<0)
return true;
299 if (mpq_cmp(a.
p->
rat,b.
p->
rat)>0)
return false;
305 if (mpq_cmp(a.
p->
rat,b.
p->
rat)>0)
return true;
311 if (mpq_cmp(a.
p->
rat,b.
p->
rat)<0)
return false;
317 if (mpq_equal(a.
p->
rat,b.
p->
rat))
return true;
323 if (mpq_equal(a.
p->
rat,b.
p->
rat))
return false;
336 snum = mpz_get_str(
NULL,10,mpq_numref(a.
p->
rat) );
337 sdenom = mpz_get_str(
NULL,10,mpq_denref(a.
p->
rat) );
339 if( sdenom[0] ==
'1' && sdenom[1] ==
'\0' )
341 #ifdef GMPRAT_IOSTREAM 344 fprintf( stdout,snum );
349 #ifdef GMPRAT_IOSTREAM 350 s << snum <<
"/" << sdenom;
352 fprintf( stdout,snum );
353 fprintf( stdout,
"/" );
354 fprintf( stdout,sdenom );
367 char *snum = (
char*)
omAlloc(mpz_sizeinbase(mpq_numref(
p->
rat),10)+2);
368 char *sden = (
char*)
omAlloc(mpz_sizeinbase(mpq_denref(
p->
rat),10)+2);
370 snum = mpz_get_str( snum,10,mpq_numref(
p->
rat ) );
371 sden = mpz_get_str( sden,10,mpq_denref(
p->
rat ) );
373 int length = strlen( snum );
375 if( sden[0] !=
'1' || sden[1] !=
'\0' ) length += strlen( sden ) + 1;
418 for(
int i=0;
i<e;
i++ )
435 return mpq_sgn(a.
p->
rat);
444 if (mpq_sgn(a.
p->
rat)<0)
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 ) );
490 for(
int i=2;
i<n;
i++ )
521 for(
int i=2;
i<n;
i++ )
531 double num = mpz_get_d( mpq_numref(
p->
rat ) );
532 double den = mpz_get_d( mpq_denref(
p->
rat ) );
534 if( num < 0 ) num = -
num;
535 if( den < 0 ) den = -
den;
537 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)