[35aab3] | 1 | // ---------------------------------------------------------------------------- |
---|
| 2 | // GMPrat.h |
---|
| 3 | // begin of file |
---|
| 4 | // originally written by Gerd Sussner, sussner@mi.uni-erlangen.de |
---|
| 5 | // copied by Stephan Endrass, endrass@mathematik.uni-mainz.de |
---|
| 6 | // 23.7.99 |
---|
| 7 | // ---------------------------------------------------------------------------- |
---|
| 8 | |
---|
| 9 | #ifndef GMPRAT_H |
---|
| 10 | #define GMPRAT_H |
---|
| 11 | |
---|
[f5de43] | 12 | #include "si_gmp.h" |
---|
[35aab3] | 13 | |
---|
| 14 | class Rational |
---|
| 15 | { |
---|
| 16 | struct rep |
---|
| 17 | { |
---|
| 18 | mpq_t rat; |
---|
| 19 | int n; |
---|
| 20 | rep() { n=1; } |
---|
| 21 | }; |
---|
| 22 | |
---|
| 23 | rep *p; |
---|
| 24 | static Rational save; |
---|
| 25 | |
---|
| 26 | void disconnect(); |
---|
| 27 | |
---|
| 28 | public: |
---|
| 29 | |
---|
| 30 | Rational( ); |
---|
| 31 | Rational( int ); |
---|
| 32 | Rational( const Rational& ); |
---|
| 33 | Rational( const Rational&,const Rational& ); |
---|
| 34 | Rational( int,int ); |
---|
| 35 | ~Rational( ); |
---|
| 36 | |
---|
| 37 | Rational& operator = ( int ); |
---|
| 38 | Rational& operator = ( char *s ); |
---|
| 39 | Rational& operator = ( const Rational& ); |
---|
| 40 | |
---|
| 41 | unsigned int length( ) const; |
---|
| 42 | Rational get_num( ); |
---|
| 43 | Rational get_den( ); |
---|
| 44 | int get_num_si( ); |
---|
| 45 | int get_den_si( ); |
---|
| 46 | operator int( ); |
---|
| 47 | |
---|
| 48 | Rational operator - ( ); |
---|
| 49 | Rational operator ~ ( ); |
---|
| 50 | Rational& operator += ( const Rational& ); |
---|
| 51 | Rational& operator -= ( const Rational& ); |
---|
| 52 | Rational& operator *= ( const Rational& ); |
---|
| 53 | Rational& operator /= ( const Rational& ); |
---|
| 54 | Rational& operator ++ ( ); |
---|
| 55 | Rational operator ++ ( int ); |
---|
| 56 | Rational& operator -- ( ); |
---|
| 57 | Rational operator -- ( int ); |
---|
| 58 | |
---|
| 59 | friend Rational operator - ( const Rational& ); |
---|
| 60 | |
---|
| 61 | friend bool operator < ( const Rational&,const Rational& ); |
---|
| 62 | friend bool operator <= ( const Rational&,const Rational& ); |
---|
| 63 | friend bool operator > ( const Rational&,const Rational& ); |
---|
| 64 | friend bool operator >= ( const Rational&,const Rational& ); |
---|
| 65 | friend bool operator == ( const Rational&,const Rational& ); |
---|
| 66 | friend bool operator != ( const Rational&,const Rational& ); |
---|
| 67 | |
---|
| 68 | #ifdef GMPRAT_PRINT |
---|
| 69 | friend ostream& operator<<( ostream&,const Rational& ); |
---|
| 70 | #endif |
---|
| 71 | |
---|
| 72 | friend int sgn ( const Rational& ); |
---|
| 73 | friend Rational abs ( const Rational& ); |
---|
| 74 | friend Rational pow ( const Rational&,int ); |
---|
| 75 | |
---|
| 76 | double complexity( ) const; |
---|
| 77 | |
---|
| 78 | friend Rational gcd ( const Rational&, const Rational& ); |
---|
| 79 | friend Rational lcm ( const Rational&, const Rational& ); |
---|
| 80 | friend Rational gcd ( Rational*, int ); |
---|
| 81 | friend Rational lcm ( Rational*, int ); |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | Rational operator + ( const Rational&, const Rational& ); |
---|
| 85 | Rational operator - ( const Rational&, const Rational& ); |
---|
| 86 | Rational operator * ( const Rational&, const Rational& ); |
---|
| 87 | Rational operator / ( const Rational&, const Rational& ); |
---|
| 88 | |
---|
| 89 | #endif /* GMPRAT_H */ |
---|
| 90 | |
---|
| 91 | // ---------------------------------------------------------------------------- |
---|
| 92 | // GMPrat.h |
---|
| 93 | // end of file |
---|
| 94 | // ---------------------------------------------------------------------------- |
---|
| 95 | |
---|