source: git/factory/int_int.h @ 63be42

fieker-DuValspielwiese
Last change on this file since 63be42 was f1295f, checked in by Jens Schmidt <schmidt@…>, 26 years ago
* int_rat.cc, int_int.cc, int_rat.h, int_int.h, int_poly.h (isZero, isOne): methods removed. Declarations adapted. * int_int.cc (neg): doc fixes. Slightly speeded up. git-svn-id: file:///usr/local/Singular/svn/trunk@2241 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: int_int.h,v 1.9 1998-06-26 16:16:40 schmidt Exp $ */
3
4#ifndef INCL_INT_INT_H
5#define INCL_INT_INT_H
6
7#include <config.h>
8
9#ifndef NOSTREAMIO
10#include <iostream.h>
11#endif /* NOSTREAMIO */
12
13#include "assert.h"
14
15#include "int_cf.h"
16#include "cf_gmp.h"
17#include "gmpext.h"
18
19class InternalInteger : public InternalCF
20{
21private:
22    MP_INT thempi;
23
24    // auxilliary methods
25    inline InternalCF * normalizeMyself ();
26    inline InternalCF * uiNormalizeMyself ();
27
28    static inline InternalCF * normalizeMPI ( MP_INT & );
29    static inline InternalCF * uiNormalizeMPI ( MP_INT & );
30
31    static inline MP_INT & MPI ( const InternalCF * const c );
32
33public:
34    InternalInteger();
35    InternalInteger( const InternalCF& )
36    {
37        ASSERT( 0, "ups there is something wrong in your code" );
38    }
39    InternalInteger( const int i );
40    InternalInteger( const char * str );
41    InternalInteger( const MP_INT & );
42    ~InternalInteger();
43    InternalCF* deepCopyObject() const;
44    const char * const classname() const { return "InternalInteger"; }
45#ifndef NOSTREAMIO
46    void print( ostream&, char* );
47#endif /* NOSTREAMIO */
48    InternalCF* genZero();
49    InternalCF* genOne();
50
51    bool is_imm() const;
52
53    int levelcoeff() const { return IntegerDomain; }
54    InternalCF* neg();
55
56    int comparesame( InternalCF* );
57
58    InternalCF* addsame( InternalCF* );
59    InternalCF* subsame( InternalCF* );
60    InternalCF* mulsame( InternalCF* );
61    InternalCF* dividesame( InternalCF* );
62    InternalCF* modulosame( InternalCF* );
63    InternalCF* divsame( InternalCF* );
64    InternalCF* modsame( InternalCF* );
65    void divremsame( InternalCF*, InternalCF*&, InternalCF*& );
66    bool divremsamet( InternalCF*, InternalCF*&, InternalCF*& );
67
68    int comparecoeff( InternalCF* );
69
70    InternalCF* addcoeff( InternalCF* );
71    InternalCF* subcoeff( InternalCF*, bool );
72    InternalCF* mulcoeff( InternalCF* );
73    InternalCF* dividecoeff( InternalCF*, bool );
74    InternalCF* modulocoeff( InternalCF*, bool );
75    InternalCF* divcoeff( InternalCF*, bool );
76    InternalCF* modcoeff( InternalCF*, bool );
77    void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
78    bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
79
80    InternalCF * bgcdsame ( const InternalCF * const ) const;
81    InternalCF * bgcdcoeff ( const InternalCF * const );
82
83    InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & );
84    InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
85
86    int intval() const;
87
88    int intmod( int p ) const;
89
90    int sign() const;
91
92    InternalCF* sqrt();
93
94    int ilog2();
95   
96    friend class InternalRational;
97#ifdef SINGULAR
98    friend MP_INT gmp_numerator ( const CanonicalForm & f );
99    friend MP_INT gmp_denominator ( const CanonicalForm & f );
100#endif /* SINGULAR */
101    friend MP_INT getmpi ( InternalCF * value, bool symmetric );
102};
103
104//{{{ inline InternalCF * InternalInteger::normalizeMyself, uiNormalizeMyself ()
105//{{{ docu
106//
107// normalizeMyself(), uiNormalizeMyself() - normalize CO.
108//
109// If CO fits into an immediate integer, delete CO and return the
110// immediate.  Otherwise, return a pointer to CO.
111//
112// `uiNormalizeMyself()' is the same as `normalizeMyself()'
113// except that CO is expected to be non-begative.  In this case,
114// we may use `mpz_get_ui()' to convert the underlying mpi into
115// an immediate which is slightly faster than the signed variant.
116//
117// Note: We do not mind reference counting at this point!  CO is
118// deleted unconditionally!
119//
120//}}}
121inline InternalCF *
122InternalInteger::normalizeMyself ()
123{
124    ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
125
126    if ( mpz_is_imm( &thempi ) ) {
127        InternalCF * result = int2imm( mpz_get_si( &thempi ) );
128        delete this;
129        return result;
130    } else
131        return this;
132}
133
134inline InternalCF *
135InternalInteger::uiNormalizeMyself ()
136{
137    ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
138
139    if ( mpz_is_imm( &thempi ) ) {
140        InternalCF * result = int2imm( mpz_get_ui( &thempi ) );
141        delete this;
142        return result;
143    } else
144        return this;
145}
146//}}}
147
148//{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( MP_INT & aMpi )
149//{{{ docu
150//
151// normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
152//
153// If `aMpi' fits into an immediate integer, clear `aMpi' and
154// return the immediate.  Otherwise, return a new
155// `InternalInteger' with `aMpi' as underlying mpi.
156//
157// `uiNormalizeMPI()' is the same as `normalizeMPI()' except that
158// `aMpi' is expected to be non-begative.  In this case, we may
159// use `mpz_get_ui()' to convert `aMpi' into an immediate which
160// is slightly faster than the signed variant.
161//
162//}}}
163inline InternalCF *
164InternalInteger::normalizeMPI ( MP_INT & aMpi )
165{
166    if ( mpz_is_imm( &aMpi ) ) {
167        InternalCF * result = int2imm( mpz_get_si( &aMpi ) );
168        mpz_clear( &aMpi );
169        return result;
170    } else
171        return new InternalInteger( aMpi );
172}
173
174inline InternalCF *
175InternalInteger::uiNormalizeMPI ( MP_INT & aMpi )
176{
177    if ( mpz_is_imm( &aMpi ) ) {
178        InternalCF * result = int2imm( mpz_get_ui( &aMpi ) );
179        mpz_clear( &aMpi );
180        return result;
181    } else
182        return new InternalInteger( aMpi );
183}
184//}}}
185
186//{{{ inline MP_INT & InternalInteger::MPI ( const InternalCF * const c )
187//{{{ docu
188//
189// MPI() - return underlying mpi of `c'.
190//
191// `c' is expected to be an `InternalInteger *'.  `c's underlying
192// mpi is returned.
193//
194//}}}
195inline MP_INT &
196InternalInteger::MPI ( const InternalCF * const c )
197{
198    return (((InternalInteger*)c)->thempi);
199}
200//}}}
201
202#endif /* ! INCL_INT_INT_H */
Note: See TracBrowser for help on using the repository browser.