1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id$ */ |
---|
3 | |
---|
4 | #ifndef INCL_INT_RAT_H |
---|
5 | #define INCL_INT_RAT_H |
---|
6 | |
---|
7 | // #include "config.h" |
---|
8 | |
---|
9 | #ifndef NOSTREAMIO |
---|
10 | #ifdef HAVE_IOSTREAM |
---|
11 | #include <iostream> |
---|
12 | #define OSTREAM std::ostream |
---|
13 | #elif defined(HAVE_IOSTREAM_H) |
---|
14 | #include <iostream.h> |
---|
15 | #define OSTREAM ostream |
---|
16 | #endif |
---|
17 | #endif /* NOSTREAMIO */ |
---|
18 | |
---|
19 | #include "cf_assert.h" |
---|
20 | |
---|
21 | #include "canonicalform.h" |
---|
22 | #include "int_cf.h" |
---|
23 | #include "imm.h" |
---|
24 | // #include "cf_gmp.h" |
---|
25 | |
---|
26 | class InternalRational : public InternalCF |
---|
27 | { |
---|
28 | private: |
---|
29 | mpz_t _num; |
---|
30 | mpz_t _den; |
---|
31 | static int initialized; |
---|
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 ); |
---|
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 ); |
---|
44 | InternalRational( const mpz_ptr ); |
---|
45 | InternalRational( const mpz_ptr , const mpz_ptr ); |
---|
46 | ~InternalRational(); |
---|
47 | InternalCF* deepCopyObject() const; |
---|
48 | const char * classname() const { return "InternalRational"; } |
---|
49 | #ifndef NOSTREAMIO |
---|
50 | void print( OSTREAM&, char* ); |
---|
51 | #endif /* NOSTREAMIO */ |
---|
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* ); |
---|
67 | InternalCF* mulsame( InternalCF* ); |
---|
68 | InternalCF* dividesame( InternalCF* ); |
---|
69 | InternalCF* modulosame( InternalCF* ); |
---|
70 | InternalCF* divsame( InternalCF* ); |
---|
71 | InternalCF* modsame( InternalCF* ); |
---|
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 ); |
---|
79 | InternalCF* mulcoeff( InternalCF* ); |
---|
80 | InternalCF* dividecoeff( InternalCF*, bool ); |
---|
81 | InternalCF* modulocoeff( InternalCF*, bool ); |
---|
82 | InternalCF* divcoeff( InternalCF*, bool ); |
---|
83 | InternalCF* modcoeff( InternalCF*, bool ); |
---|
84 | void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool ); |
---|
85 | bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ); |
---|
86 | |
---|
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 | |
---|
93 | int intval() const; |
---|
94 | |
---|
95 | int sign() const; |
---|
96 | |
---|
97 | InternalCF * normalize_myself(); |
---|
98 | |
---|
99 | friend class InternalInteger; |
---|
100 | friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result ); |
---|
101 | friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result ); |
---|
102 | friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d ); |
---|
103 | }; |
---|
104 | |
---|
105 | inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c ) |
---|
106 | { |
---|
107 | return (((InternalRational*)c)->_num); |
---|
108 | } |
---|
109 | |
---|
110 | inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c ) |
---|
111 | { |
---|
112 | return (((InternalRational*)c)->_den); |
---|
113 | } |
---|
114 | |
---|
115 | #endif /* ! INCL_INT_RAT_H */ |
---|