Talk:Prime decomposition: Difference between revisions

Line 70:
 
I'm reverting the last change of array size from 8 to 30, since it's mathematically impossible to have more (or fewer than) 8 numbers after each run. If you disagree because some diagnostic software says other wise, show me where it will fail. --[[User:Ledrug|Ledrug]] 20:59, 7 September 2011 (UTC)
 
: The program fails because it crashes and dumps core! However, I fixed it wrong and made the size too large: it only needs to be 9, not 30.
 
: <lang c> for (i = 1, q = p; i <= 30; i++, q += p) {
if (!(b[n] = bit_pos[q % 30])) continue;
b[n] = ~b[n];
shift[n++] = q / 30;
}</lang>
 
: I missed that bit_pos[] has only 8 nonzero elements. After this loop fills b[0] to b[7], it continues to assign b[8] = 0, because the assignment is before the <code>continue</code> statement. Therefore, program must declare array b[9] to hold elements b[0] to b[8]. --[[User:Kernigh|Kernigh]] 22:29, 7 September 2011 (UTC)
Anonymous user