/* File: pi800.c Name: Program for Analyzing alien PI computing Author: zyl910 Blog: http://blog.csdn.net/zyl910/ Version: V1.0 Updata: 2006-11-5 Program for Analyzing alien PI computing ~~~~~~~~~~~~~~~~~~~~~~ Original program: Int A = 10000, B, c = 2800, d, e, f [2801], G; Main (){ For (; B-c ;) F [B ++] = A/5; For (; D = 0, G = C * 2; C-= 14, printf ("%. 4D", e + D/A), E = D %) For (B = C; D + = f [B] * A, F [B] = D % -- g, D/= g --, -- B; D * = B ); } Pi formula: 1 2 3 K Pi = 2 + --- * (2 + --- * (2 + --- * (2 +... (2 + ---- * (2 + ...))...))) 3 5 7 2 k + 1 */ Int main (void) { Long A = 10000; // Scaling Factor Long c = 2800; // number of iterations Long f [2801]; // intermediate Calculation Result Long D; // cumulative inner cycle error Long E = 0; // cumulative error of external circulation Long B, G; // molecules and denominator. K/(2 k + 1) Int I, J; For (I = 0; I <C; I ++) // If you fully follow the formula, the cycle condition should be "for (I = 1; I <= C; I ++) ". Fortunately, F [2800] has a very small contribution, and getting any value will not have a big impact on accuracy. F [I] = 2 * A/10; // 2 is the coefficient 2 in the formula. A/10 indicates that a decimal bit is retained, because the output starts from 3. While (C> 0) { D = 0; G = (C * 2 + 1)-2; // denominator. Because 4 bits are output in each loop, we multiply the number of bits in the subsequent operation by a, so here we have to-2 B = C; // molecule While (B> 0) { /* Multiply by the numerator according to the formula */ D * = B; D + = f [B] * A; // because each External Loop outputs four digits /* Divide by the denominator according to the formula */ F [B] = D % G; // part of the numerator with a score D/= g; // an integer with a score /* Next */ G-= 2; B --; } Printf ("%. 4D", e + D/); E = D %; C-= 14; // because the precision is fixed to 800 bits, after every 4 bits are output, it is equivalent to reducing the precision requirement by 4 bits, so 14 items can be counted at a time } Printf ("/N "); Return 0; } |