Calculating Pi


I stumbled on a neat bit of C code when looking at the PB-2000C (a C-capable calculator, which is weird enough by itself). The code calculates Pi to any number of places. Here's it is...

long a=10000,b,c,d,e,*f,g;

Compiled and ran it on my machine. I don't understand how it works, but it does. Could anyone with a bit of math skills please comment on what's actually happening here? It looks like magic to me.



It looks like magic to me.

Spigot (

Read Pi Unleashed. Ch. 6 for a detailed explanation.

For Unbounded Spigot checkout:

A C version of the Unbounded Spigot:

Edited: 3 July 2012, 11:30 a.m.


.... wow.

Edited: 3 July 2012, 4:55 p.m. after one or more responses were posted


Side note - libtommath is in use in the 39gII.

I've never found any good speed comparision between that and other (free/commercial) libraries. Anyone seen one before anywhere?


Edited: 3 July 2012, 3:24 p.m.


I have a fairly comprehensive beta version of a longfloat library written in hpgcc3 for hp50g.
It is user accessible, and it is based on decnumber.
I'm fairly confident it will outpermform similar librarys for any hpcalculator.
Send me a note if you want to give it a try.
Best regards


I'm fairly confident it will outpermform similar librarys for any hpcalculator.

Agreed for FP, but not for INT. libtommath is much faster for large integer math. At least based on the comparisons I did years ago.


Hi again,

I agree, there are (much) faster librarys for special purposes.

My library is suitable for floating point evaluation up to about 1000 digits for real and complex values.

It is accessible from user-rpl, you set number of floating point digits, and can directly evaluate expresions like e.g.

'4*ATAN(1)' ->FNUM

100 digits in 0,1s , 200 digits in 0,4s, 500 digits in 4,1s

'SQRT(-2)' ->FNUM

1000 digits in 0,1s, 10000 digits 11,2s

except for basic arithmetic there is a limit of about 1000 DIGITS

Best regards


Possibly Related Threads...
Thread Author Replies Views Last Post
  [OT] Mathematica free for Raspberry PI BruceH 32 2,577 11-23-2013, 05:24 AM
Last Post: Nick_S
  Computing pi with the PC-1300S Kiyoshi Akima 0 278 11-17-2013, 12:24 AM
Last Post: Kiyoshi Akima
  [HP Prime] Calculating Prandtl Number with Units (bug found in USIMPLIFY) Timothy Roche 1 373 11-13-2013, 04:07 PM
Last Post: cyrille de Brébisson
  Calculating Pi LHH 9 821 09-27-2013, 10:50 PM
Last Post: Gerson W. Barbosa
  Visualization of pi Bruce Bergman 13 1,086 08-17-2013, 05:00 PM
Last Post: Howard Owen
  OT: Happy Pi Day! Eddie W. Shore 13 1,129 03-22-2013, 10:44 AM
Last Post: Les Koller
  Totally OT ... Pi Day for my car Maximilian Hohmann 18 1,400 03-10-2013, 01:15 PM
Last Post: chris smith
  [WP34S] A funny bug in Pi (prod) Eduardo Duenez 3 522 01-28-2013, 03:41 AM
Last Post: Walter B
  28S Pi Functionality Matt Fegenbush 3 459 10-17-2012, 02:15 AM
Last Post: Nick_S
  e^pi - pi + 9/10^4 + 1/(10^4*ln(2) + sqrt(10)/6)^2 Gerson W. Barbosa 47 3,505 08-08-2012, 10:58 PM
Last Post: Les Koller

Forum Jump: