Changeset 4fb4f3 in git
 Timestamp:
 Jul 22, 2010, 1:13:53 PM (14 years ago)
 Branches:
 (u'fiekerDuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b52fc4b2495505785981d640dcf7eb3e456778ef')
 Children:
 c9208c6142738462cca70025492057ebce264baf
 Parents:
 ad0c5c42970dfab59d4ca1c9afc9fe369b894106
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

kernel/rmodulo2m.cc
rad0c5c r4fb4f3 151 151 { 152 152 NATNUMBER nn = (unsigned long)(NATNUMBER)n & r>nr2mModul; 153 unsigned long l = r>nr2mModul >> 1; l++; 154 if (l == 0) 155 return (int)(signed long)(NATNUMBER)nn; 156 else if ((NATNUMBER)nn > l) 153 unsigned long l = r>nr2mModul >> 1; l++; /* now: l = 2^(m1) */ 154 if ((NATNUMBER)nn > l) 157 155 return (int)((NATNUMBER)nn  r>nr2mModul  1); 158 156 else … … 210 208 } 211 209 210 /* This does not seem to be the predicate whether a 211 is divisible by b in Z/2^m: if a is NULL then 212 the answer is not necessarily TRUE. */ 212 213 BOOLEAN nr2mDivBy (number a, number b) 213 214 { 214 if ((NATNUMBER)a == 0) return TRUE; 215 if ((NATNUMBER)b == 0) return FALSE; 216 return ((NATNUMBER)a % (NATNUMBER)b) == 0; 215 if (a == NULL) 216 { 217 NATNUMBER c = currRing>nr2mModul + 1; 218 if (c != 0) /* i.e., if no overflow */ 219 return (c % (NATNUMBER)b) == 0; 220 else 221 { 222 /* overflow: we need to check whether b 223 is a power of 2: */ 224 c = (NATNUMBER)b; 225 while (c != 0) 226 { 227 if ((c % 2) != 0) return FALSE; 228 c = c >> 1; 229 } 230 return TRUE; 231 } 232 } 233 else 234 return ((NATNUMBER)a % (NATNUMBER)b) == 0; 217 235 } 218 236 … … 391 409 } 392 410 393 number nr2mIntDiv (number a,number b) 394 { 395 assume((NATNUMBER)b != 0); 396 return (number) ((NATNUMBER) a / (NATNUMBER) b); 411 number nr2mIntDiv (number a, number b) 412 { 413 if ((NATNUMBER)a == 0) 414 { 415 if ((NATNUMBER)b == 0) 416 return (number)1; 417 if ((NATNUMBER)b == 1) 418 return (number)0; 419 NATNUMBER c = currRing>nr2mModul + 1; 420 if (c != 0) /* i.e., if no overflow */ 421 return (number)(c / (NATNUMBER)b); 422 else 423 { 424 /* overflow: c = 2^32 resp. 2^64, depending on platform */ 425 int_number cc = (int_number)omAlloc(sizeof(mpz_t)); 426 mpz_init_set_ui(cc, currRing>nr2mModul); mpz_add_ui(cc, cc, 1); 427 mpz_div_ui(cc, cc, (unsigned long)(NATNUMBER)b); 428 unsigned long s = mpz_get_ui(cc); 429 mpz_clear(cc); omFree((ADDRESS)cc); 430 return (number)(NATNUMBER)s; 431 } 432 } 433 else 434 { 435 if ((NATNUMBER)b == 0) 436 return (number)0; 437 return (number)((NATNUMBER) a / (NATNUMBER) b); 438 } 397 439 } 398 440
Note: See TracChangeset
for help on using the changeset viewer.