Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!zehntel!tektronix!reed!keith From: keith@reed.UUCP (Packard) Newsgroups: net.math Subject: Re: multiple-precision arithmetic Message-ID: <732@reed.UUCP> Date: Thu, 29-Nov-84 00:31:23 EST Article-I.D.: reed.732 Posted: Thu Nov 29 00:31:23 1984 Date-Received: Sun, 2-Dec-84 04:00:01 EST References: <163@faron.UUCP> Reply-To: keith@reed.UUCP (PUT YOUR NAME HERE) Organization: Reed College, Portland, Oregon Lines: 96 I have a very good use for multi precision arithmetic. I have already written my own (not the best but functional) in C for the VAX as a part of a package that includes a pseudo machine that executes code generated by a compiler doing multi precision rational arithmetic. The compiler accepts a large subset of C as input. The pseudo machine is implemented as a stack machine with several built in functions: scanf, printf, gcd, ... As a bench mark, my pseudo machine computes the primes to 100 in 3.4 seconds (sorry it's so slow): /* * compute prime numbers using a silly algorithm */ main () { auto i,j,k, limit, c; printf ("limit: "); scanf ("%d", limit); c = 2; printf ("2\t3\t"); for (i = 5; i < limit; i = i + 2) { j = sqrt (i, 4); for (k = 3; k <= j; k += 2) { if (~ i % k) { goto bad; } } printf ("%d", i); if ((c += 1) == 8) { c = 0; printf ("\n"); } else printf ("\t"); bad: ; } if (c) printf ("\n"); } sqrt (n, m) { auto i, t, j; j = int (n / 2); /* note built in function int */ for (i = 0; i < m; i += 1) { if ((t = int (n / j)) == j) return j; j = int ((t + j) / 2); } return j; } but it computes the factorial of 100: 9332621544394415268169923885626670049071596826438162146859296389521759999322991 5608941463976156518286253697920827223758251185210916864000000000000000000000000 in only 0.3 seconds main () { /* * note storage class used instead of type, no types in * this language */ auto i; while (scanf ("%d", i) == 1) printf ("%d\n", i!); exit (0); /* actually returns 0 all the way back to the shell! */ } I have basically finished with this project but if I found better arithmetic routines (better than those found in Knuth) I would certainly like to include them. I am a compiler writer by nature, this complicated math stuff takes too much work to verify, out of ~5000 lines of code for this system, the 1500 lines of math routines took at least 50% of the time to get working. I am willing to distribute this package to anyone interested. Unfortunately, the math routines are rather VAX specific I think they will work on a 16032 or any other 32 bit machine with correct byte order but, I have not tested this (even though I have access to a 16032 machine running 4.2 unix, if you want to know if it works I could ethernet the sources down there and try it before sending the whole mess.) keith packard ...tektronix!reed!keith or ...tektronix!tekmdp!keithp - no sources here but a better connection