Well the hardware discussions here over the past few days have been running hot and heavy, so I thought I'd start a new software discussion to sort of balance things out. This is a story about PI (the mathematical constant, not the raspberry kind).
I've built up a hard disk image that you can download here:
SC131 PI Hard Disk - hd_pi.imgfor experimenting with computing PI on the SC131 using various programming languages and algorithms.
What's on the disk:
PI.C and PI.COM A 16-bit program for computing PI up to 22904 decimal places
PI.SUB A submit file for building PI.COM from PI.C using Aztec C (included)
PI-OL.C and PI-OL.CPM A somewhat faster 16-bit program for computing PI up to 16275 decimal places
PI-OL.SUB A submit file for building PI-OL.COM from PI-OL.C using Aztec C (included)
PIZ88.C and PIZ88.COM PI.C compilable with and cross-compiled by Z88DK on a modern host computer
PIZ88.BAT A Windows/DOS batch file for building PIZ88.COM from PIZ88.C using Z88DK
PI-OLZ88.C and PI-OLZ88.COM PI-OL.C compilable with and cross-compiled by Z88DK on a modern host computer
PI-OLZ88.BAT A Windows/DOS batch file for building PI-OLZ88.COM from PI-OLZ88.C using Z88DK
PI.BAS An MBASIC (included) program for computing PI (ported from PI.C by Tom Lake)
PI32.C 32-bit version of PI.C that you can compile/run on your favorite modern computer
TIMEPI.SUB Submit file for timing PI.COM (runs TIMER before and after)
TIMEPIOL.SUB Submit file for timing PI-OL.COM (runs TIMER before and after)
TIMEPIZ8.SUB Submit file for timing PIZ88.COM (runs TIMER before and after)
TIMEPOZ8.SUB Submit file for timing PI-OLZ88.COM (runs TIMER before and after)
A little history on this project:
While playing around with a language called FOCAL on my AltairDuino, I ran across a program for computing PI written in FOCAL for the SOL20 by a fellow named Paul Schaper. While the program is fundamentally incomprehensible to me, I learned that it was of a class of algorithms for computing PI known as spigot algorithms. I ported the program to C, compiled it with Aztec C for CP/M, ran it on the AltairDuino, and shared it with the members of the AltairDuino Google group. This led to a discussion which uncovered another spigot algorithm, implemented as one-line of C by Dik Winter based on an algorithm by Rabinowitz & Wagon. I unwound the one-line implementation and de-obfuscated it, then generalized it to allow the number of decimal places to be user specified; this I also compiled with Aztec C for CP/M and ran on the AltairDuino. One thing I quickly realized about both of these programs - they were very slow at Altair 8800 speeds and the compute time for PI increased roughly as the square of the number of decimal places computed.
Since the SC131 is running roughly 9 times faster than an Altair 8800, I first moved these programs over to the SC131 using XM and ran them. Sure enough, they did run about 9 times faster. The original algorithm (PI.C) computed PI to 100 decimal places in 31 seconds, vs. ~270 seconds on the AltairDuino; while the unwound "one-line" algorithm (PI-OL.C) computed PI to 100 decimal places in 19 seconds, vs. ~175 seconds on the AltairDuino.
Then I discovered the cross-compiler Z88DK! When I compiled these two programs for CP/M with Z88DK, I found that the executable programs generated by this more modern compiler technology (vs. Aztec C) ran MUCH faster. PI.C compiled this way (
PIZ88.COM) can compute 100 decimal places in just 9 seconds; PI-OL.C compiled this way (
PI-OLZ88.COM) can compute the same 100 decimal places in just 6 seconds. I also tried the Z88DK-compiled versions on the AltairDuino with similar speed increases there (though I had to configure the AltairDuino to use a Z80 processor rather than the 8080). I tried to use Z88DK to generate 8080 code but ran into assorted compile errors, so I gave up on that; if anyone knows how to generate pure 8080 code using Z88DK, I'd appreciate advice.
PI.C, when compiled for a 16-bit system, can correctly compute PI to 22904 decimal places. You probably wouldn't want to wait for that many places because it would still take more than 80 hours even using the Z88DK-compiled version
PIZ88.COM.
PI-OL.c when compiled for a 16-bit or 32-bit system, can correctly compute PI to 16275 decimal places but will run out of memory for more than 2851 decimal places (with a 55302 byte CP/M TPA). If you happen to boot ZPM3 which has a 60422 byte TPA, it will compute up to 3215 decimal places. Because
PI-OLZ88.COM is smaller than
PI-OL.COM, it can compute a few hundered more digits without running out of memory.
PI-OLZ88.COM computes 2851 decimal places in 2620 seconds;
Also included on the disk image is an MBASIC version of the first algorithm (PI.BAS), ported by Tom Lake of the AltairDuino group. That runs really, REALLY slow, as you might imagine! It can only compute up to about 1984 decimal places and that will take 7 hours or so.
Lastly, on the disk image is the source code for the 32-bit version of the program that can compute PI to at least 1,000,000 decimal places. If you copy that off and compile it with gcc on a modern Intel Core i5 machine, it will gladly compute PI to 100,000 places in maybe 3 minutes, or to 1,000,000 places in less than 5 hours. It's not too shabby on a Raspberry Pi 3 model B either at about 15 minutes for 100,000 places.
You can verify that these programs are computing the correct result by consulting this web site:
https://www.angio.net/pi/digits.htmlIf you download the disk image, you can image it to an SD card by itself (as slice 0), or copy it onto the end of the combo image (as slice 6) or to the end of any single disk image (as slice 1). The disk will boot to ZSDOS (the NZCOM version) so that you can run the things on it, but will contain only the files necessary for this project, not all of the usual CP/M utilities, so you may want to boot from a different disk and just use this as a data disk; if you happen to boot CP/M 3, you should use A:SUBMIT or SUBMIT3 (instead of SUBMIT) on this disk to run any of the .SUB files.