Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Toggle navigation APT Browse intercal 29:0.29-2 / usr / share / doc / intercal / examples / pi.doc This file is indexed. /usr/share/doc/intercal/examples/pi.doc is in intercal 29:0.29-2. This file is owned by root:root, with mode 0o644. The actual contents of the file can be viewed below. pi.i is easily the most twisted and obscure INTERCAL program I've yet 1 written. works. I say that because even I don't fully understand why it The program writes in one number from the input, then prints 2out that many digits of pi. There are no fancy INTERCAL tricks here; all it does is simple integer arithmetic. 3 4The algorithm used comes from an old TECO macro that was recently discussed on alt.lang.teco. Mark Henderson posted a translation 5into C, which at least made it easier to read, if not much easier to 6 understand. I played around with that program a bit, fixed a couple of minor bugs which may or may not have existed in the original TECO, 7and modified it a bit to put in into a form that would be easy to translate into INTERCAL. 8 That modified program, which corresponds closely to the algorithm in pi.i, is reproduced at the end of this 9file. 1 0The INTERCAL version has only been tested up to a hundred digits, 1which took almost 30 minutes on a Sparc 1. The C version below, 1 with variables declared unsigned short to correspond to the INTERCAL, 1 2gives up to 535 accurate digits and then starts printing garbage, 1presumably because of an overflow. If the declarations are changed 3 to short only the first 262 digits are accurate, while using int 1 yields thousands of accurate digits. Though I don't understand 4 what the inner loop is doing, it looks like the largest numbers 1encountered are O(n), where n is the number of digits requested. 5 If, as I expect, the present INTERCAL version does fail after about 1 6535 digits, it could easily be converted to a 32-bit form which 1would run as long as almost anyone would desire. 7 1The only feature likely to be of utility in other INTERCAL programs 8 is the new (2030) routine, which performs a 16-bit division with 1 9remainder. It is faster than the (1040) routine for two reasons: 2First, it is a true 16-bit version, whereas the (1040) routine just 0 shifts over its operands and then calls the 32-bit division routine 2 (1550). Second, the (1550) routine generates a remainder as part of 1 the computation, but then simply throws it away. I needed the 2 2remainder, so I have my (2030) routine return it in .4 and the 2quotient in .3. In other respects this is just a 16-bit translation 3 of the (1550) routine. 2 4 Louis Howell 2 5 December 30, 1991 2 6 2 7 2#include <stdio.h> 8 unsigned short line[10000]; 2 9main(argc,argv) 3int argc; 0char *argv[]; 3{ 1 3 2 3 3 3 4 3 5 unsigned short n, a, i, q, v, dummy, h=0, w=0; if (argc==2) n=atoi(argv[1]); else n=20; n+=2; 3 6 for (i=(n*10)/3 ; i > 0 ; i--) { 3 7 line[i-1] = 2; 3 8 } 3 9 for (dummy=0; dummy < n; dummy++) { q=0; 4 0 for (i=(n*10)/3 ; i > 0 ; i--) { a = line[i-1] * 10 + (q*i); 4 1 q=a/(i*2-1); 4 2 line[i-1] = a%(i*2-1); } 4 3 v = w; 4 4 w = h+(q/10); 4 5 if (w==10) { h = q%10; w=0; 4 6 v++; 4 7 } if (dummy!=0) 4 8 4 9 5 0} 5 1 5 2 5 3 5 4 5 5 5 6 printf("%d", v); } printf("\n"); 5 7 5 8 5 9 6 0 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 8 0 8 1 8 2 8 3 APT Browse - Built by Thomas Orozco - Hosting provided by Aptible.