Computing pi on Z80-based calculators

From 1990 until at least 2010, TI calculators were Z80 powered and for a lot of people they were their first and most convenient Z80 platform.


(Credit: Frank P)

I came across a thread by Frank P on Google Groups about calculating pi on the TI-83 and there’s a zip file included with Basic, C, and calculator versions of two different algorithms. Plenty of detail inside about tools and equipment needed:
Computing PI in BASIC and C on a quite different Z80 system ca. 1996

all the programs I’ve seen online for the TI only calculate PI to 9 decimal places (given that TI BASIC’s floating point precision is 10 significant figures). I had already coded two arbitrary precision PI programs in C based on the prior works of Paul Schaper and Dik Winter, and one of these had already been translated into Microsoft BASIC by Tom Lake, and implemented in some form or another on an emulated 8080 (AltairDuino), Z180 (SC131), ESP8266 (MakerPhone), and assorted Windows and Linux systems. I documented the SC131 project here: https://groups.google.com/g/retro-comp/c/3LKv-TYwfZ0 .

… I first translated the second C program to MBASIC, then proceeded to translate them both to TI-BASIC 83 (which I discovered is VERY different from MBASIC) and hand-enter them on the TI-83… These two programs are based on different “spigot” algorithms, and they have different characteristics

PI - Based on a FOCAL program by Paul Schaper written for the SOL20 using an algorithm of unknown origin:

  • A more complex algorithm that is slower (than PIOL) but quite frugal with its memory usage, able to compute up to 983 decimal places in TI-BASIC 83 (but it will take ~36 hours, 52 minutes :slight_smile:

PIOL - Based on a One-Line C program by Dik Winter using an algorithm attributed to Rabinowitz & Wagon:

  • A simpler algorithm that is faster (than PI) but uses more memory, able to compute up to only 28 decimal places in TI-BASIC 83.

Some results:

Not surprisingly at all, the compiled C programs ran MUCH faster on the TI-83 than their BASIC counterparts. Here are some typical timings for computing PI to 40 decimal places:
300 seconds - PI in TI-BASIC 83
85 seconds - PIOL in TI-BASIC 83
4.5 seconds - PI in C
3 seconds = PIOL in C

At their upper limits, PI takes ~4.6 hours to correctly compute 2683 decimal places, and PI-OL takes 455 seconds to correctly compute 567 decimal places.

About the tooling, in case you want to try this at home:

First and foremost (since most people don’t have a TI-83 just lying around) is the TI calculator emulator known as “Vti”. You can download it here: Virtual TI v2.5 beta 5 - ticalc.org . It does not come with ROM images; you can download ROM images here: Texas Instruments TI 83 roms, games and ISOs to download for emulation

1 Like

My main problem with talking to the Z80 on my TI-83 is bit-rot on the connection software. There’s nothing for Mac OS, and the Linux software is all “run this graphical thing as root, it’ll be totes fine” …

1 Like