C Code to calculate PI on my Z80

103 views
Skip to first unread message

Peter Onion

unread,
Sep 8, 2025, 11:40:39 AMSep 8
to RC2014-Z80
Spigot400.png
We've been playing with a bit of code on some of  the museum machines that calculates PI with a very odd algorithm, so I thought I should try it on my Z80.  It only needs integer arithmetic, but it does need 32 bit integers so it's not particularly fast, 3:25 for 400 digits.
PeterO

S P Dixon

unread,
Sep 8, 2025, 1:06:02 PMSep 8
to rc201...@googlegroups.com

I love this stuff, do you have details of the algorithm? (I'm just really curious about how it works.)

Shiela


--
You received this message because you are subscribed to the Google Groups "RC2014-Z80" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rc2014-z80+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/rc2014-z80/1037874b-b0fb-4881-8b2b-690bc01a70d6n%40googlegroups.com.
<Spigot400.png>

Peter Onion

unread,
Sep 8, 2025, 1:26:49 PMSep 8
to RC2014-Z80
Shiela,

We got the original "obfuscated C" code from this paper : https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf

We were talking to some visitors to TNMOC about this last Saturday.  It turned out one of them knows the person that wrote that paper !  They commented "That's typical of the things he does!".

I've attached a version for modern C (tested on gcc)  For Hi-Tech C on the Z80 just change uint32_t to long and remove the second #include line.

Have fun,

PeterO
spigot.c

Martin Giese

unread,
Sep 9, 2025, 8:43:30 AMSep 9
to RC2014-Z80
This seems to be the original reference for the Rabinowitz and Wagon “spigot algorithm”:


Martin

Peter Onion

unread,
Sep 9, 2025, 9:45:44 AMSep 9
to rc201...@googlegroups.com
On Tue, 2025-09-09 at 05:43 -0700, Martin Giese wrote:
> This seems to be the original reference for the Rabinowitz and Wagon “spigot algorithm”:
> https://www.jstor.org/stable/2975006
>
> PDF here: http://stanleyrabinowitz.com/bibliography/spigot.pdf
>
> Martin

Yes, I have that paper in my "Downloads" directory. I also have a version of the PASCAL
code from there translated to ALGOL-60 to run on the ELLIOTT 803, but it is rather slow !

PeterO

PauldB

unread,
Sep 9, 2025, 10:39:41 AMSep 9
to RC2014-Z80
I agree, this stuff is a lot of fun.

Some years back during Covid, Frank P. posted a conversation where he was "experimenting with computing PI on the SC131 using various programming languages and algorithms". There's some interesting stuff there.

Paul

Reply all
Reply to author
Forward
Message has been deleted
0 new messages