[493c477] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[341696] | 2 | /* $Id$ */ |
---|
[2dd068] | 3 | |
---|
[493c477] | 4 | #ifndef INCL_INT_RAT_H |
---|
| 5 | #define INCL_INT_RAT_H |
---|
[2dd068] | 6 | |
---|
[e4fe2b] | 7 | // #include "config.h" |
---|
[9d7aaa] | 8 | |
---|
[718e670] | 9 | #ifndef NOSTREAMIO |
---|
[1dc616] | 10 | #ifdef HAVE_IOSTREAM |
---|
| 11 | #include <iostream> |
---|
[181148] | 12 | #define OSTREAM std::ostream |
---|
[1dc616] | 13 | #elif defined(HAVE_IOSTREAM_H) |
---|
[2dd068] | 14 | #include <iostream.h> |
---|
[181148] | 15 | #define OSTREAM ostream |
---|
[1dc616] | 16 | #endif |
---|
[718e670] | 17 | #endif /* NOSTREAMIO */ |
---|
| 18 | |
---|
[650f2d8] | 19 | #include "cf_assert.h" |
---|
[718e670] | 20 | |
---|
[05d0b3] | 21 | #include "canonicalform.h" |
---|
[2dd068] | 22 | #include "int_cf.h" |
---|
[05d0b3] | 23 | #include "imm.h" |
---|
[ee668e] | 24 | // #include <factory/cf_gmp.h> |
---|
[2dd068] | 25 | |
---|
| 26 | class InternalRational : public InternalCF |
---|
| 27 | { |
---|
| 28 | private: |
---|
[a52291] | 29 | mpz_t _num; |
---|
| 30 | mpz_t _den; |
---|
[2dd068] | 31 | static int initialized; |
---|
[a52291] | 32 | static mpz_ptr MPQNUM( const InternalCF * const c ); |
---|
| 33 | static mpz_ptr MPQDEN( const InternalCF * const c ); |
---|
| 34 | static void normalize( const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr ); |
---|
[2dd068] | 35 | public: |
---|
| 36 | InternalRational(); |
---|
| 37 | InternalRational( const InternalCF& ) |
---|
| 38 | { |
---|
| 39 | ASSERT( 0, "ups there is something wrong in your code" ); |
---|
| 40 | } |
---|
| 41 | InternalRational( const int i ); |
---|
| 42 | InternalRational( const int n, const int d ); |
---|
| 43 | InternalRational( const char * str ); |
---|
[a52291] | 44 | InternalRational( const mpz_ptr ); |
---|
| 45 | InternalRational( const mpz_ptr , const mpz_ptr ); |
---|
[2dd068] | 46 | ~InternalRational(); |
---|
| 47 | InternalCF* deepCopyObject() const; |
---|
[c770dc] | 48 | const char * classname() const { return "InternalRational"; } |
---|
[718e670] | 49 | #ifndef NOSTREAMIO |
---|
[181148] | 50 | void print( OSTREAM&, char* ); |
---|
[718e670] | 51 | #endif /* NOSTREAMIO */ |
---|
[2dd068] | 52 | InternalCF* genZero(); |
---|
| 53 | InternalCF* genOne(); |
---|
| 54 | |
---|
| 55 | bool is_imm() const; |
---|
| 56 | int levelcoeff() const { return RationalDomain; } |
---|
| 57 | |
---|
| 58 | InternalCF* num(); |
---|
| 59 | InternalCF* den(); |
---|
| 60 | |
---|
| 61 | InternalCF* neg(); |
---|
| 62 | |
---|
| 63 | int comparesame( InternalCF* ); |
---|
| 64 | |
---|
| 65 | InternalCF* addsame( InternalCF* ); |
---|
| 66 | InternalCF* subsame( InternalCF* ); |
---|
[718e670] | 67 | InternalCF* mulsame( InternalCF* ); |
---|
[2dd068] | 68 | InternalCF* dividesame( InternalCF* ); |
---|
| 69 | InternalCF* modulosame( InternalCF* ); |
---|
[718e670] | 70 | InternalCF* divsame( InternalCF* ); |
---|
| 71 | InternalCF* modsame( InternalCF* ); |
---|
[2dd068] | 72 | void divremsame( InternalCF*, InternalCF*&, InternalCF*& ); |
---|
| 73 | bool divremsamet( InternalCF*, InternalCF*&, InternalCF*& ); |
---|
| 74 | |
---|
| 75 | int comparecoeff( InternalCF* ); |
---|
| 76 | |
---|
| 77 | InternalCF* addcoeff( InternalCF* ); |
---|
| 78 | InternalCF* subcoeff( InternalCF*, bool ); |
---|
[718e670] | 79 | InternalCF* mulcoeff( InternalCF* ); |
---|
[2dd068] | 80 | InternalCF* dividecoeff( InternalCF*, bool ); |
---|
| 81 | InternalCF* modulocoeff( InternalCF*, bool ); |
---|
[718e670] | 82 | InternalCF* divcoeff( InternalCF*, bool ); |
---|
[2dd068] | 83 | InternalCF* modcoeff( InternalCF*, bool ); |
---|
| 84 | void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool ); |
---|
| 85 | bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ); |
---|
| 86 | |
---|
[05d0b3] | 87 | InternalCF * bgcdsame ( const InternalCF * const ) const; |
---|
| 88 | InternalCF * bgcdcoeff ( const InternalCF * const ); |
---|
| 89 | |
---|
| 90 | InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & ); |
---|
| 91 | InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & ); |
---|
| 92 | |
---|
[2dd068] | 93 | int intval() const; |
---|
| 94 | |
---|
| 95 | int sign() const; |
---|
| 96 | |
---|
| 97 | InternalCF * normalize_myself(); |
---|
| 98 | |
---|
| 99 | friend class InternalInteger; |
---|
[8357930] | 100 | friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result ); |
---|
| 101 | friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result ); |
---|
[a52291] | 102 | friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d ); |
---|
[2dd068] | 103 | }; |
---|
| 104 | |
---|
[a52291] | 105 | inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c ) |
---|
[2dd068] | 106 | { |
---|
| 107 | return (((InternalRational*)c)->_num); |
---|
| 108 | } |
---|
| 109 | |
---|
[a52291] | 110 | inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c ) |
---|
[2dd068] | 111 | { |
---|
| 112 | return (((InternalRational*)c)->_den); |
---|
| 113 | } |
---|
| 114 | |
---|
[493c477] | 115 | #endif /* ! INCL_INT_RAT_H */ |
---|