Changeset 73fa1c in git
- Timestamp:
- Jun 25, 2010, 3:10:19 PM (13 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 7c9b7da4a277bda3742ad28d7a37f4d01591b5dc
- Parents:
- e3b3168b5d15b9433ea6b864e17b0d261c58c36d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/misc_ip.cc
re3b3168 r73fa1c 1 1 /*****************************************************************************\ 2 * Computer Algebra System SINGULAR 2 * Computer Algebra System SINGULAR 3 3 \*****************************************************************************/ 4 /** @file misc .cc4 /** @file misc_ip.cc 5 5 * 6 6 * This file provides miscellaneous functionality. 7 7 * 8 8 * For more general information, see the documentation in 9 * misc .h.9 * misc_ip.h. 10 10 * 11 11 * @author Frank Seelisch … … 20 20 #include "lists.h" 21 21 #include "longrat.h" /* We only need bigints. */ 22 #include "misc .h"22 #include "misc_ip.h" 23 23 24 24 /* This works by Newton iteration, i.e., … … 30 30 number approximateSqrt(const number n) 31 31 { 32 if (nlIsZero(n)) { return nlInit(0, NULL); }32 if (nlIsZero(n)) { number zero = nlInit(0, NULL); return zero; } 33 33 number temp1; number temp2; 34 34 number one = nlInit(1, NULL); … … 42 42 temp1 = nlIntDiv(m, two); 43 43 temp2 = nlIntDiv(nHalf, m); 44 nlDelete(&mOld, NULL);45 44 mOld = m; 46 45 m = nlAdd(temp1, temp2); … … 63 62 nlDelete(&m, NULL); 64 63 nlDelete(&one, NULL); 65 return temp1; 64 m = temp1; 65 return m; 66 66 } 67 67 … … 124 124 int offset = i % 32; 125 125 unsigned int v = 1 << offset; 126 if (value) ii[index] |= v; 127 else ii[index] &= (~v); 126 if (value && ((ii[index] & v) != 0)) return; 127 if ((!value) && ((ii[index] & v) == 0)) return; 128 if (value && ((ii[index] & v) == 0)) { ii[index] += v; return; } 129 if ((!value) && ((ii[index] & v) != 0)) { ii[index] -= v; return; } 128 130 } 129 131 … … 172 174 for (i = 0; i < s; i++) isPrime[i] = 4294967295; /* all 32 bits set */ 173 175 int p = 5; bool add2 = true; 174 while ((p <= maxP) && (isLeq(p, nn))) 176 /* due to possible overflows, we need to check whether p > 0, and 177 likewise i > 0 below */ 178 while ((0 < p) && (p <= maxP) && (isLeq(p, nn))) 175 179 { 176 180 /* at this point, p is guaranteed to be a prime; … … 182 186 /* invalidate all multiples of p, starting with 2*p */ 183 187 i = 2 * p; 184 while ( i <= s) { setValue(i, false, isPrime); i += p; }188 while ((0 < i) && (i <= s)) { setValue(i, false, isPrime); i += p; } 185 189 /* move on to the next prime in the sieve; we either add 2 or 4 186 190 in order to visit just the numbers equal to -1/+1 mod 6 */ 187 191 if (add2) { p += 2; add2 = false; } 188 192 else { p += 4; add2 = true; } 189 while (( p <= maxP) && (isLeq(p, nn)) && (!getValue(p, isPrime)))193 while ((0 < p) && (p <= maxP) && (isLeq(p, nn)) && (!getValue(p, isPrime))) 190 194 { 191 195 if (add2) { p += 2; add2 = false; }
Note: See TracChangeset
for help on using the changeset viewer.