Changeset fc732a9 in git for factory/int_int.h
- Timestamp:
- Mar 17, 1998, 4:59:42 PM (26 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- e0fb8d31ff69374db7f865baedfda3e614804382
- Parents:
- bb17e813fdec9082fa78763093e18795ea0fdbb4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/int_int.h
rbb17e8 rfc732a9 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_int.h,v 1. 7 1998-01-22 10:54:22schmidt Exp $ */2 /* $Id: int_int.h,v 1.8 1998-03-17 15:56:18 schmidt Exp $ */ 3 3 4 4 #ifndef INCL_INT_INT_H … … 7 7 #include <config.h> 8 8 9 #include "cf_gmp.h"10 9 #ifndef NOSTREAMIO 11 10 #include <iostream.h> … … 15 14 16 15 #include "int_cf.h" 16 #include "cf_gmp.h" 17 #include "gmpext.h" 17 18 18 19 class InternalInteger : public InternalCF … … 20 21 private: 21 22 MP_INT thempi; 22 static int initialized; 23 static MP_INT & MPI( const InternalCF * const c ); 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 24 33 public: 25 34 InternalInteger(); … … 95 104 }; 96 105 97 inline MP_INT & InternalInteger::MPI( const InternalCF * const c ) 106 //{{{ inline InternalCF * InternalInteger::normalizeMyself, uiNormalizeMyself () 107 //{{{ docu 108 // 109 // normalizeMyself(), uiNormalizeMyself() - normalize CO. 110 // 111 // If CO fits into an immediate integer, delete CO and return the 112 // immediate. Otherwise, return a pointer to CO. 113 // 114 // `uiNormalizeMyself()' is the same as `normalizeMyself()' 115 // except that CO is expected to be non-begative. In this case, 116 // we may use `mpz_get_ui()' to convert the underlying mpi into 117 // an immediate which is slightly faster than the signed variant. 118 // 119 // Note: We do not mind reference counting at this point! CO is 120 // deleted unconditionally! 121 // 122 //}}} 123 inline InternalCF * 124 InternalInteger::normalizeMyself () 125 { 126 ASSERT( getRefCount() == 1, "internal error: must not delete CO" ); 127 128 if ( mpz_is_imm( &thempi ) ) { 129 InternalCF * result = int2imm( mpz_get_si( &thempi ) ); 130 delete this; 131 return result; 132 } else 133 return this; 134 } 135 136 inline InternalCF * 137 InternalInteger::uiNormalizeMyself () 138 { 139 ASSERT( getRefCount() == 1, "internal error: must not delete CO" ); 140 141 if ( mpz_is_imm( &thempi ) ) { 142 InternalCF * result = int2imm( mpz_get_ui( &thempi ) ); 143 delete this; 144 return result; 145 } else 146 return this; 147 } 148 //}}} 149 150 //{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( MP_INT & aMpi ) 151 //{{{ docu 152 // 153 // normalizeMPI(), uiNormalizeMPI() - normalize a mpi. 154 // 155 // If `aMpi' fits into an immediate integer, clear `aMpi' and 156 // return the immediate. Otherwise, return a new 157 // `InternalInteger' with `aMpi' as underlying mpi. 158 // 159 // `uiNormalizeMPI()' is the same as `normalizeMPI()' except that 160 // `aMpi' is expected to be non-begative. In this case, we may 161 // use `mpz_get_ui()' to convert `aMpi' into an immediate which 162 // is slightly faster than the signed variant. 163 // 164 //}}} 165 inline InternalCF * 166 InternalInteger::normalizeMPI ( MP_INT & aMpi ) 167 { 168 if ( mpz_is_imm( &aMpi ) ) { 169 InternalCF * result = int2imm( mpz_get_si( &aMpi ) ); 170 mpz_clear( &aMpi ); 171 return result; 172 } else 173 return new InternalInteger( aMpi ); 174 } 175 176 inline InternalCF * 177 InternalInteger::uiNormalizeMPI ( MP_INT & aMpi ) 178 { 179 if ( mpz_is_imm( &aMpi ) ) { 180 InternalCF * result = int2imm( mpz_get_ui( &aMpi ) ); 181 mpz_clear( &aMpi ); 182 return result; 183 } else 184 return new InternalInteger( aMpi ); 185 } 186 //}}} 187 188 //{{{ inline MP_INT & InternalInteger::MPI ( const InternalCF * const c ) 189 //{{{ docu 190 // 191 // MPI() - return underlying mpi of `c'. 192 // 193 // `c' is expected to be an `InternalInteger *'. `c's underlying 194 // mpi is returned. 195 // 196 //}}} 197 inline MP_INT & 198 InternalInteger::MPI ( const InternalCF * const c ) 98 199 { 99 200 return (((InternalInteger*)c)->thempi); 100 201 } 202 //}}} 101 203 102 204 #endif /* ! INCL_INT_INT_H */
Note: See TracChangeset
for help on using the changeset viewer.