Changeset 0461f0 in git for libpolys/coeffs/modulop.cc
- Timestamp:
- Jul 21, 2011, 10:00:44 PM (12 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- bc1fdba5e0c00a808f45922f0d0fe8c4ec086e88
- Parents:
- a778e6518804aecf7bb83784c8936b0868f52943
- git-author:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-07-21 22:00:44+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:53:31+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/modulop.cc
ra778e6 r0461f0 31 31 BOOLEAN npGreaterZero (number k, const coeffs r) 32 32 { 33 assume( n_Test(k, r) ); 34 33 35 int h = (int)((long) k); 34 36 return ((int)h !=0) && (h <= (r->npPrimeM>>1)); … … 45 47 number npMult (number a,number b, const coeffs r) 46 48 { 49 assume( n_Test(a, r) ); 50 assume( n_Test(b, r) ); 51 47 52 if (((long)a == 0) || ((long)b == 0)) 48 53 return (number)0; 49 else 50 return npMultM(a,b, r); 54 number c = npMultM(a,b, r); 55 assume( n_Test(c, r) ); 56 return c; 51 57 } 52 58 … … 57 63 { 58 64 long ii=i; 59 long p=(long)ABS(r->ch); 60 while (ii < 0L) ii += p; 61 while ((ii>1L) && (ii >= p)) ii -= p; 62 return (number)ii; 63 } 64 65 while (ii < 0L) ii += (long)r->ch; 66 while ((ii>1L) && (ii >= ((long)r->ch))) ii -= (long)r->ch; 67 68 number c = (number)ii; 69 assume( n_Test(c, r) ); 70 return c; 71 72 } 73 74 75 #if 0 65 76 /*2 66 * convert a number to an int in (-p/2 .. p/2] 67 */ 77 * convert a number to an int in (-p/2 .. p/2] 78 * BUG: InConsistent: nInit(nInt(a)) != a, for a in (p/2, p) 79 */ 68 80 int npInt(number &n, const coeffs r) 69 81 { 82 assume( n_Test(n, r) ); 83 70 84 if ((long)n > (((long)r->ch) >>1)) return (int)((long)n -((long)r->ch)); 71 85 else return (int)((long)n); 72 86 } 87 #else 88 /*2 89 * convert a number to an int in [0 .. p) 90 */ 91 int npInt(number &n, const coeffs r) 92 { 93 assume( n_Test(n, r) ); 94 95 return (int)(long)n; 96 } 97 #endif 73 98 74 99 number npAdd (number a, number b, const coeffs r) 75 100 { 76 return npAddM(a,b, r); 101 assume( n_Test(a, r) ); 102 assume( n_Test(b, r) ); 103 104 number c = npAddM(a,b, r); 105 106 assume( n_Test(c, r) ); 107 108 return c; 77 109 } 78 110 79 111 number npSub (number a, number b, const coeffs r) 80 112 { 81 return npSubM(a,b,r); 82 } 83 84 BOOLEAN npIsZero (number a, const coeffs) 85 { 113 assume( n_Test(a, r) ); 114 assume( n_Test(b, r) ); 115 116 number c = npSubM(a,b,r); 117 118 assume( n_Test(c, r) ); 119 120 return c; 121 } 122 123 BOOLEAN npIsZero (number a, const coeffs r) 124 { 125 assume( n_Test(a, r) ); 126 86 127 return 0 == (long)a; 87 128 } 88 129 89 BOOLEAN npIsOne (number a, const coeffs) 90 { 130 BOOLEAN npIsOne (number a, const coeffs r) 131 { 132 assume( n_Test(a, r) ); 133 91 134 return 1 == (long)a; 92 135 } … … 94 137 BOOLEAN npIsMOne (number a, const coeffs r) 95 138 { 139 assume( n_Test(a, r) ); 140 96 141 return ((r->npPminus1M == (long)a)&&((long)1!=(long)a)); 97 142 } … … 144 189 inline number npInversM (number c, const coeffs r) 145 190 { 191 assume( n_Test(c, r) ); 146 192 #ifndef HAVE_DIV_MOD 147 return(number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];193 number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]]; 148 194 #else 149 195 long inv=(long)r->npInvTable[(long)c]; … … 153 199 r->npInvTable[(long)c]=inv; 154 200 } 155 return (number)inv; 156 #endif 201 number d = (number)inv; 202 #endif 203 assume( n_Test(d, r) ); 204 return d; 205 157 206 } 158 207 159 208 number npDiv (number a,number b, const coeffs r) 160 209 { 210 assume( n_Test(a, r) ); 211 assume( n_Test(b, r) ); 212 161 213 //#ifdef NV_OPS 162 214 // if (npPrimeM>NV_MAX_PRIME) … … 165 217 if ((long)a==0) 166 218 return (number)0; 219 number d; 220 167 221 #ifndef HAVE_DIV_MOD 168 222 if ((long)b==0) … … 171 225 return (number)0; 172 226 } 173 else 174 { 175 int s = r->npLogTable[(long)a] - r->npLogTable[(long)b]; 176 if (s < 0) 177 s += r->npPminus1M; 178 return (number)(long)r->npExpTable[s]; 179 } 227 228 int s = r->npLogTable[(long)a] - r->npLogTable[(long)b]; 229 if (s < 0) 230 s += r->npPminus1M; 231 d = (number)(long)r->npExpTable[s]; 180 232 #else 181 233 number inv=npInversM(b,r); 182 return npMultM(a,inv,r); 183 #endif 234 d = npMultM(a,inv,r); 235 #endif 236 237 assume( n_Test(d, r) ); 238 return d; 239 184 240 } 185 241 number npInvers (number c, const coeffs r) 186 242 { 243 assume( n_Test(c, r) ); 244 187 245 if ((long)c==0) 188 246 { … … 190 248 return (number)0; 191 249 } 192 return npInversM(c,r); 250 number d = npInversM(c,r); 251 252 assume( n_Test(d, r) ); 253 return d; 254 193 255 } 194 256 195 257 number npNeg (number c, const coeffs r) 196 258 { 259 assume( n_Test(c, r) ); 260 197 261 if ((long)c==0) return c; 198 return npNegM(c,r); 199 } 200 201 BOOLEAN npGreater (number a,number b, const coeffs) 202 { 262 263 #if 0 264 number d = npNegM(c,r); 265 assume( n_Test(d, r) ); 266 return d; 267 #else 268 c = npNegM(c,r); 269 assume( n_Test(c, r) ); 270 return c; 271 #endif 272 } 273 274 BOOLEAN npGreater (number a,number b, const coeffs r) 275 { 276 assume( n_Test(a, r) ); 277 assume( n_Test(b, r) ); 278 203 279 //return (long)a != (long)b; 204 280 return (long)a > (long)b; … … 207 283 BOOLEAN npEqual (number a,number b, const coeffs r) 208 284 { 285 assume( n_Test(a, r) ); 286 assume( n_Test(b, r) ); 287 209 288 // return (long)a == (long)b; 289 210 290 return npEqualM(a,b,r); 211 291 } … … 213 293 void npWrite (number &a, const coeffs r) 214 294 { 295 assume( n_Test(a, r) ); 296 215 297 if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a))); 216 298 else StringAppend("%d",(int)((long)a)); … … 219 301 void npPower (number a, int i, number * result, const coeffs r) 220 302 { 303 assume( n_Test(a, r) ); 304 221 305 if (i==0) 222 306 { … … 281 365 } 282 366 } 367 assume( n_Test(*a, r) ); 283 368 return s; 284 369 }
Note: See TracChangeset
for help on using the changeset viewer.