Happy Pi Day

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: Happy Pi Day

Post by drogon »

Martin_H wrote:
BigDumbDinosaur wrote:
Uh...I’ll get my coat and quietly exit.  :D
With puns like that I was hoping you'd be here all week.

@Gordon, thanks for the details. I was going to ask how you achieved that many digits, as I was suspecting the Spigot algorithm. I'd considered using that to avoid arbitrary precision arithmetic. But the hexadecimal to decimal conversion seems like a harder problem. BTW Google offered to translate your BCPL program from Danish to English.
Maybe more Double Dutch than Danish then ;-)

Curiously I was thinking that I may be the last remaining BCPL programmer on the planet (After Martin Richards), however a brief "chat" With Claude AI shows that Claude knows BCPL quite well and started to write a Fortran compiler for me - in BCPL.

It has given me ideas though...

BTW: That code isn't mine. You may want to read to accompanying article: https://unicorn.drogon.net/pi.pdf

As for spiggot.. I know there are some good results over on startdot - here is something else in hex:

Code: Select all

Pi in hex

       3.
    1: 243F6A8885A308D313198A2E03707344A4093822299F31D008
   51: 2EFA98EC4E6C89452821E638D01377BE5466CF34E90C6CC0AC
  101: 29B7C97C50DD3F84D5B5B54709179216D5D98979FB1BD1310B
  151: A698DFB5AC2FFD72DBD01ADFB7B8E1AFED6A267E96BA7C9045
  201: F12C7F9924A19947B3916CF70801F2E2858EFC16636920D871
  251: 574E69A458FEA3F4933D7E0D95748F728EB658718BCD588215
  301: 4AEE7B54A41DC25A59B59C30D5392AF26013C5D1B023286085
  351: F0CA417918B8DB38EF8E79DCB0603A180E6C9E0E8BB01E8A3E
  401: D71577C1BD314B2778AF2FDA55605C60E65525F3AA55AB9457
  451: 48986263E8144055CA396A2AAB10B6B4CC5C341141E8CEA154
  501: 86AF7C72E993B3EE1411636FBC2A2BA9C55D741831F6CE5C3E
  551: 169B87931EAFD6BA336C24CF5C7A325381289586773B8F4898
  601: 6B4BB9AFC4BFE81B6628219361D809CCFB21A991487CAC605D
  651: EC8032EF845D5DE98575B1DC262302EB651B8823893E81D396
  701: ACC50F6D6FF383F442392E0B4482A484200469C8F04A9E1F9B
  751: 5E21C66842F6E96C9A670C9C61ABD388F06A51A0D2D8542F68
  801: 960FA728AB5133A36EEF0B6C137A3BE4BA3BF0507EFB2A98A1
  851: F1651D39AF017666CA593E82430E888CEE8619456F9FB47D84
  901: A5C33B8B5EBEE06F75D885C12073401A449F56C16AA64ED3AA
  951: 62363F77061BFEDF72429B023D37D0D724D00A1248DB0FEAD3

Pi in decimal

       3.
    1: 14159265358979323846264338327950288419716939937510
   51: 58209749445923078164062862089986280348253421170679
  101: 82148086513282306647093844609550582231725359408128
  151: 48111745028410270193852110555964462294895493038196
  201: 44288109756659334461284756482337867831652712019091
  251: 45648566923460348610454326648213393607260249141273
  301: 72458700660631558817488152092096282925409171536436
  351: 78925903600113305305488204665213841469519415116094
  401: 33057270365759591953092186117381932611793105118548
  451: 07446237996274956735188575272489122793818301194912
  501: 98336733624406566430860213949463952247371907021798
  551: 60943702770539217176293176752384674818467669405132
  601: 00056812714526356082778577134275778960917363717872
  651: 14684409012249534301465495853710507922796892589235
  701: 42019956112129021960864034418159813629774771309960
  751: 51870721134999999837297804995105973173281609631859
  801: 50244594553469083026425223082533446850352619311881
  851: 71010003137838752886587533208381420617177669147303
  901: 59825349042875546873115956286388235378759375195778
  951: 18577805321712268066130019278766111959092164201989
Time: 33234mS
that 33 seconds was on the RISC-V system - by the time it printed that out the '816 system had barely started the 2nd row...

https://unicorn.drogon.net/pidigs.b.txt

Enjoy :)

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: Happy Pi Day Three Days Early

Post by barnacle »

BigDumbDinosaur wrote:
barnacle wrote:
Surely, the 31st of April... for countries with a sensible date system :mrgreen:
Go home, Neil.  Yer drunk!
I did wonder if anyone would notice :mrgreen:

Neil
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Happy Pi Day

Post by Martin_H »

@Gordon, with that many Pi digits, it's obvious that I need to up my game next year. I see arbitrary precision packed decimal numbers in my future. All I need is four basic arithmetic functions and it's off to the races.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Happy Pi Day

Post by BigEd »

drogon wrote:
You don't need scaled integers - the code does it all for you. All you need is simple manipulation of 32-bit quantities. Plus, minus, multiply, divide and modulo. There is no floating point, no trig. involved. The code evaluates arctan using integers.

Using Störmer’s formula:

Code: Select all

π = 24 arctan(1/8) + 8 arctan(1/57) + 4 arctan(1/239)
The code uses 3 arrays to maintain the calculations. Each array element entry packs 8 decimal digits per 32-bit word, so using 3 banks of 64K per array you can calculate up to half a million digits... given sufficient time...
Nice work - good choice of formula!

Another choice which works well needs only 2 arrays, so the capacity is higher. And Katie Wasserman has already done a lot of the work, so a port should be not too difficult. I don't know how the speed might compare. See over on stardot (from 2022):
Pi Day - many digits of Pi (again, twice)

I did more recently do some experiments using iterated x=x+sin(x) but it ended up looking like being slower and also needing more storage. See my repo
iterating x+sin(x) to compute pi with retrocomputers
Post Reply