source: git/factory/int_rat.h @ 37f64cb

spielwiese
Last change on this file since 37f64cb was abddbe, checked in by Martin Lee <martinlee84@…>, 10 years ago
chg: added brief descriptions to some files
  • Property mode set to 100644
File size: 3.7 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifndef INCL_INT_RAT_H
4#define INCL_INT_RAT_H
5
6/**
7 * @file int_rat.h
8 *
9 * Factory's internal rationals
10**/
11// #include "config.h"
12
13#ifndef NOSTREAMIO
14#ifdef HAVE_IOSTREAM
15#include <iostream>
16#define OSTREAM std::ostream
17#elif defined(HAVE_IOSTREAM_H)
18#include <iostream.h>
19#define OSTREAM ostream
20#endif
21#endif /* NOSTREAMIO */
22
23#include "cf_assert.h"
24
25#include "canonicalform.h"
26#include "int_cf.h"
27#include "imm.h"
28// #include <factory/cf_gmp.h>
29
30/**
31 * factory's class for rationals
32 *
33 * a rational is represented as two mpz_t's _num, _den
34 *
35 * Note: If you want to compute over Q make sure that SW_RATIONAL is set to 1!
36 *
37 * @sa InternalInteger
38**/
39class InternalRational : public InternalCF
40{
41private:
42    mpz_t _num;
43    mpz_t _den;
44    static int initialized;
45    static mpz_ptr MPQNUM( const InternalCF * const c );
46    static mpz_ptr MPQDEN( const InternalCF * const c );
47    static void normalize( const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr );
48public:
49    InternalRational();
50    InternalRational( const InternalCF& )
51    {
52        ASSERT( 0, "ups there is something wrong in your code" );
53    }
54    InternalRational( const int i );
55    InternalRational( const int n, const int d );
56    InternalRational( const long i );
57    InternalRational( const long n, const long d );
58    InternalRational( const char * str );
59    InternalRational( const mpz_ptr );
60    InternalRational( const mpz_ptr , const mpz_ptr );
61    ~InternalRational();
62    InternalCF* deepCopyObject() const;
63    const char * classname() const { return "InternalRational"; }
64#ifndef NOSTREAMIO
65    void print( OSTREAM&, char* );
66#endif /* NOSTREAMIO */
67    InternalCF* genZero();
68    InternalCF* genOne();
69
70    bool is_imm() const;
71    int levelcoeff() const { return RationalDomain; }
72
73    InternalCF* num();
74    InternalCF* den();
75
76    InternalCF* neg();
77
78    int comparesame( InternalCF* );
79
80    InternalCF* addsame( InternalCF* );
81    InternalCF* subsame( InternalCF* );
82    InternalCF* mulsame( InternalCF* );
83    InternalCF* dividesame( InternalCF* );
84    InternalCF* modulosame( InternalCF* );
85    InternalCF* divsame( InternalCF* );
86    InternalCF* modsame( InternalCF* );
87    void divremsame( InternalCF*, InternalCF*&, InternalCF*& );
88    bool divremsamet( InternalCF*, InternalCF*&, InternalCF*& );
89
90    int comparecoeff( InternalCF* );
91
92    InternalCF* addcoeff( InternalCF* );
93    InternalCF* subcoeff( InternalCF*, bool );
94    InternalCF* mulcoeff( InternalCF* );
95    InternalCF* dividecoeff( InternalCF*, bool );
96    InternalCF* modulocoeff( InternalCF*, bool );
97    InternalCF* divcoeff( InternalCF*, bool );
98    InternalCF* modcoeff( InternalCF*, bool );
99    void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
100    bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
101
102    InternalCF * bgcdsame ( const InternalCF * const ) const;
103    InternalCF * bgcdcoeff ( const InternalCF * const );
104
105    InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & );
106    InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
107
108    long intval() const;
109
110    int sign() const;
111
112    InternalCF * normalize_myself();
113
114    friend class InternalInteger;
115    friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result );
116    friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
117    friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d );
118};
119
120inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c )
121{
122    return (((InternalRational*)c)->_num);
123}
124
125inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c )
126{
127    return (((InternalRational*)c)->_den);
128}
129
130#endif /* ! INCL_INT_RAT_H */
Note: See TracBrowser for help on using the repository browser.