Post Reply 
Creating digits of pi
02-09-2018, 01:40 PM
Post: #16
RE: Creating digits of pi
(02-09-2018 12:54 PM)toml_12953 Wrote:  
(02-09-2018 12:08 PM)Mike (Stgt) Wrote:  Sorry, I did not mention that you should take it as pseudocode only. Well, it is REXX what I boiled down to the essential loop. So a 'minor' detail went up in smoke:

numeric digits 500

what sets precision of all variables and has its effect on the loop end criterion DO..UNTIL m = m + n what is -- I confess -- an awesome concealment or simple substitution of the compare n/m < epsilon (I quit the loop when it has no influence on the result any more).

How to run REXX? Try Regina, or fast brexx from CERN, or Open Object Rexx (I used it for a HP7470A simulation), or NetRexx, or -- very outstanding -- get a mainframe under Hercules on your machine (which could be a Raspberry Pi - tested, works).

Ciao.....Mike

Here's a version in Decimal BASIC interpreter that returns 1000 digits before you can remove your finger from the Enter key on a 4.2 GHz Core i7:
(PI is a reserved word in Decimal BASIC) Wait a second. That was fun. I didn't just have fun did I? No, not me. I refuse to have fun.

Code:
OPTION ARITHMETIC DECIMAL_HIGH ! 1000 digits precision
LET s = 1
LET n = 1
LET m = 3
DO UNTIL m = m + n
   LET n = n / 9
   LET s = s + n / (m + 2) - 3 * n / m
   LET m = m + 4
LOOP
LET PIE = 2 * s * SQR(3)
PRINT PIE
END

Or the equivalent in bc:

Code:
scale = 1000
s=1
n=1
m=3
while (m != m + n) {
    n = n/9
    s = s+n / (m+2) - 3*n/m
    m = m+4
}
pi = 2*s*sqrt(3)
print pi

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Creating digits of pi - brickviking - 02-06-2018, 12:24 AM
RE: Creating digits of pi - Joe Horn - 02-06-2018, 01:38 AM
RE: Creating digits of pi - toml_12953 - 02-06-2018, 09:24 PM
RE: Creating digits of pi - brickviking - 02-06-2018, 10:38 PM
RE: Creating digits of pi - brickviking - 02-08-2018, 04:22 AM
RE: Creating digits of pi - toml_12953 - 02-08-2018, 01:02 PM
RE: Creating digits of pi - TASP - 02-07-2018, 10:30 PM
RE: Creating digits of pi - pier4r - 02-09-2018, 02:59 PM
RE: Creating digits of pi - emece67 - 02-10-2018, 09:14 PM
RE: Creating digits of pi - TASP - 02-11-2018, 12:12 AM
RE: Creating digits of pi - ttw - 02-12-2018, 03:59 AM
RE: Creating digits of pi - EdS2 - 02-17-2018, 12:27 PM
RE: Creating digits of pi - EdS2 - 02-21-2018, 11:01 AM
RE: Creating digits of pi - pier4r - 02-17-2018, 04:25 PM
RE: Creating digits of pi - brickviking - 02-17-2018, 09:27 PM
RE: Creating digits of pi - pier4r - 02-23-2018, 01:34 PM
RE: Creating digits of pi - SlideRule - 05-13-2018, 05:09 PM



User(s) browsing this thread: 1 Guest(s)