Jump to content

Recommended Posts

After 68 years I just learned about the Feynman point where six nines appear in PI.

I never had the patience to try the PI calculator that I ported from DxForth to Camel99 Forth out past 200 digits or so. 

 

This was a nice way to determine if the darned thing worked. 

It took almost six minutes and 20 seconds on real TI-99 iron. 

 

So Happy PI day. 

(I know it doesn't make much sense to all the 99er's on other continents but indulge us for a moment) :) 

 

image.png.aded644d6021a78e93d946c332b6e44b.png

Edited by TheBF
typo
  • Like 2
Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/
Share on other sites

23 minutes ago, TheBF said:

After 68 years I just learned about the Feyman point where six nines appear in PI.

I never had the patience to try the PI calculator that I ported from DxForth to Camel99 Forth out past 200 digits or so. 

 

This was a nice way to determine if the darned thing worked. 

It took almost six minutes and 20 seconds on real TI-99 iron. 

 

So Happy PI day. 

(I know it doesn't make much sense to all the 99er's on other continents but indulge us for a moment) :) 

 

image.png.aded644d6021a78e93d946c332b6e44b.png

Since it works you plan on releasing the pi code?

Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429483
Share on other sites

27 minutes ago, Gary from OPA said:

Since it works you plan on releasing the pi code?

Oh sure. It's Forth so not many people care but here it is. 

What's nice is that it includes credits back to 1978! 

 

Ed in the notes is the author of DxForth that runs on MSDOS and CPM. :) 

 

\ PI.FTH from DxForth.
\ Thanks to Ed from Australia for finding the bug in my D+
\
\ Revised 2015-02-09  es
\
\ Compute Pi to an arbitrary precision. Uses Machin's
\ formula:  pi/4 = 4 arctan(1/5) - arctan(1/239)
\
\ Compile with 16-bit DX-Forth: FORTH - INCLUDE PI.F BYE
\ Compile with CAMEL99 Forth: INCLUDE DSK*.PI  ( where * is your drive no.)
\
\ This 16-bit implementation allows up to 45,808 digits
\ to be computed before arithmetic overflow occurs.
\
\ The code can be used on 32-bit targets with appropriate
\ changes:
\
\   16-bit             32-bit
\
\   10000 Multiply     100000000 Multiply
\   <# # # # # #>      <# # # # # # # # # #>
\   4 +loop            8 +loop
\   525 um/mod         1050 um/mod
\                      remove 'digits > 45808' warning
\
\ Acknowledgements:
\
\   Roy Williams, Feb 1994
\   J. W. Stumpel, May 1991
\   E. Ford, Aug 2009
\   R. Bishop, Aug 1978
\
\ This code is PUBLIC DOMAIN. Use at your own risk.

\ Modified for Camel99 Forth  Mar 2021 Fox
NEEDS DUMP   FROM DSK1.LOWTOOLS
NEEDS VALUE  FROM DSK1.VALUES
NEEDS D=     FROM DSK1.DOUBLE
NEEDS .R     FROM DSK1.UDOTR
NEEDS ELAPSE FROM DSK1.ELAPSE
NEEDS MALLOC FROM DSK1.MALLOC

\ proper MOVE for 9900, cell wide
HEX
 CODE MOVE (addr1 addr2 len -- )
    C036 , C076 , C104 , 1306 , 0584 ,
    0244 , FFFE , CC31 , 0644 , 15FD ,
    C136 ,
 NEXT,
 ENDCODE

DECIMAL

0 VALUE POWER  ( adr)
0 VALUE TERM   ( adr)
0 VALUE RESULT ( adr)
0 VALUE SIZE   ( n)

VARIABLE CARRY

: ADD ( -- )
  CARRY OFF
  RESULT   0 SIZE 1- DO
    I CELLS OVER + ( res) DUP @ 0
    I CELLS TERM + @ 0  D+  CARRY @ M+
    ( hi) CARRY !  ( lo) SWAP ( res) !
  -1 +LOOP  DROP ;

: SUBTRACT ( -- )
  CARRY OFF
  RESULT   0 SIZE 1- DO
    I CELLS OVER + ( RES) DUP @ 0
    I CELLS TERM + @ 0  D-  CARRY @ M+
    ( HI) CARRY !  ( LO) SWAP ( RES) !
  -1 +LOOP  DROP ;

0 VALUE FACTOR

\ scan forward for cell containing non-zero
: +INDEX ( ADR -- ADR INDEX )
    -1
    BEGIN 1+ DUP SIZE -
    WHILE
       2DUP CELLS + @
    UNTIL
    THEN ;

: DIVIDE ( ADR FACTOR -- )
  TO FACTOR
  CARRY OFF
  +INDEX ( adr index ) SIZE SWAP
  ?DO
     I CELLS OVER + ( res)
     DUP @  CARRY @  FACTOR  UM/MOD
    ( quot) ROT ( res) !  ( rem) CARRY !
  LOOP
  DROP ;

\ scan backward for cell containing non-zero
: -INDEX ( adr -- adr index )
    SIZE
    BEGIN 1- DUP
    WHILE
       2DUP CELLS + @
    UNTIL
    THEN ;

: MULTIPLY ( adr factor -- )
  TO FACTOR   CARRY OFF
  -INDEX ( adr index ) 0 SWAP
  DO
    I CELLS OVER + ( res)
    DUP @  FACTOR  UM*  CARRY @ M+
    ( hi) CARRY !  ( lo) SWAP ( res) !
  -1 +LOOP
  DROP ;

: COPY ( -- ) POWER TERM SIZE CELLS MOVE ;

\ : ZERO? ( result -- f )  +INDEX NIP SIZE = ;
: ZERO? ( result -- F ) SIZE CELLS 0 SKIP NIP 0= ;

0 VALUE PASS
VARIABLE EXP
VARIABLE SIGN

: DIVISOR ( -- N )
  PASS 1 = IF  5  ELSE  239  THEN ;

: ERASE 0 FILL ;

: INITIALIZE ( -- )
  POWER SIZE CELLS ERASE
  TERM  SIZE CELLS ERASE
  PASS 1 = IF  RESULT SIZE CELLS ERASE  THEN
  16  PASS DUP * / POWER !
  POWER  DIVISOR  DIVIDE
  1 EXP !  PASS 1- SIGN ! ;

0 VALUE NDIGIT

: CalcPi ( -- )
  NDIGIT 45800 U> IF
    ." Warning: digits > 45808 will be in error " CR
  THEN

  2 1+ 1
  DO
    I TO PASS
    INITIALIZE
    BEGIN
      COPY
      TERM  EXP @ DIVIDE
      SIGN @  DUP IF  SUBTRACT  ELSE  ADD  THEN
      0= SIGN !  2 EXP +!
      POWER  DIVISOR DUP *  DIVIDE
      POWER ZERO?
    UNTIL
  LOOP ;

\ VARIABLE OUT
\ : CR  CR  0 OUT ! ;
\ : #   #   1 OUT +! ;

DECIMAL
: PRINT ( -- )
  CR
  RESULT  DUP @ 0 .R  [CHAR] . EMIT CR
  NDIGIT 0
  ?DO
    0 OVER !
    DUP 10000 MULTIPLY
    DUP @  0 <# # # # # #> TYPE SPACE
\    OUT @ C/L @ > IF CR THEN  \ not needed for Camel99
    4  +LOOP
  DROP  CR ;

: GetNumber ( -- n )
  CR ." How many digits do you want? "
  PAD DUP 20 ACCEPT NUMBER? ABORT" Invalid" CR ;

: PI ( n -- ) DUP TO NDIGIT
  \ array size = ceil(ndigit / log10(2^16))
  109 UM* 525 UM/MOD SWAP ( rem) IF  1+  THEN
  ( extra for accurate last digits)
  2 +  TO SIZE

  \ create arrays in un-allocated memory
  HERE TO POWER   SIZE 20 + CELLS ALLOT
  HERE TO TERM    SIZE 20 + CELLS ALLOT
  HERE TO RESULT  SIZE 20 + CELLS ALLOT
  50 ALLOT  ( hold buffer space)
  CalcPi
  PRINT
;
\ end

 

  • Like 1
Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429506
Share on other sites

3 minutes ago, TheBF said:

Oh sure. It's Forth so not many people care but here it is. 

What's nice is that it includes credits back to 1978! 

 

Ed in the notes is the author of DxForth that runs on MSDOS and CPM. :) 

 

\ PI.FTH from DxForth.
\ Thanks to Ed from Australia for finding the bug in my D+
\
\ Revised 2015-02-09  es
\
\ Compute Pi to an arbitrary precision. Uses Machin's
\ formula:  pi/4 = 4 arctan(1/5) - arctan(1/239)
\
\ Compile with 16-bit DX-Forth: FORTH - INCLUDE PI.F BYE
\ Compile with CAMEL99 Forth: INCLUDE DSK*.PI  ( where * is your drive no.)
\
\ This 16-bit implementation allows up to 45,808 digits
\ to be computed before arithmetic overflow occurs.
\
\ The code can be used on 32-bit targets with appropriate
\ changes:
\
\   16-bit             32-bit
\
\   10000 Multiply     100000000 Multiply
\   <# # # # # #>      <# # # # # # # # # #>
\   4 +loop            8 +loop
\   525 um/mod         1050 um/mod
\                      remove 'digits > 45808' warning
\
\ Acknowledgements:
\
\   Roy Williams, Feb 1994
\   J. W. Stumpel, May 1991
\   E. Ford, Aug 2009
\   R. Bishop, Aug 1978
\
\ This code is PUBLIC DOMAIN. Use at your own risk.

\ Modified for Camel99 Forth  Mar 2021 Fox
NEEDS DUMP   FROM DSK1.LOWTOOLS
NEEDS VALUE  FROM DSK1.VALUES
NEEDS D=     FROM DSK1.DOUBLE
NEEDS .R     FROM DSK1.UDOTR
NEEDS ELAPSE FROM DSK1.ELAPSE
NEEDS MALLOC FROM DSK1.MALLOC

\ proper MOVE for 9900, cell wide
HEX
 CODE MOVE (addr1 addr2 len -- )
    C036 , C076 , C104 , 1306 , 0584 ,
    0244 , FFFE , CC31 , 0644 , 15FD ,
    C136 ,
 NEXT,
 ENDCODE

DECIMAL

0 VALUE POWER  ( adr)
0 VALUE TERM   ( adr)
0 VALUE RESULT ( adr)
0 VALUE SIZE   ( n)

VARIABLE CARRY

: ADD ( -- )
  CARRY OFF
  RESULT   0 SIZE 1- DO
    I CELLS OVER + ( res) DUP @ 0
    I CELLS TERM + @ 0  D+  CARRY @ M+
    ( hi) CARRY !  ( lo) SWAP ( res) !
  -1 +LOOP  DROP ;

: SUBTRACT ( -- )
  CARRY OFF
  RESULT   0 SIZE 1- DO
    I CELLS OVER + ( RES) DUP @ 0
    I CELLS TERM + @ 0  D-  CARRY @ M+
    ( HI) CARRY !  ( LO) SWAP ( RES) !
  -1 +LOOP  DROP ;

0 VALUE FACTOR

\ scan forward for cell containing non-zero
: +INDEX ( ADR -- ADR INDEX )
    -1
    BEGIN 1+ DUP SIZE -
    WHILE
       2DUP CELLS + @
    UNTIL
    THEN ;

: DIVIDE ( ADR FACTOR -- )
  TO FACTOR
  CARRY OFF
  +INDEX ( adr index ) SIZE SWAP
  ?DO
     I CELLS OVER + ( res)
     DUP @  CARRY @  FACTOR  UM/MOD
    ( quot) ROT ( res) !  ( rem) CARRY !
  LOOP
  DROP ;

\ scan backward for cell containing non-zero
: -INDEX ( adr -- adr index )
    SIZE
    BEGIN 1- DUP
    WHILE
       2DUP CELLS + @
    UNTIL
    THEN ;

: MULTIPLY ( adr factor -- )
  TO FACTOR   CARRY OFF
  -INDEX ( adr index ) 0 SWAP
  DO
    I CELLS OVER + ( res)
    DUP @  FACTOR  UM*  CARRY @ M+
    ( hi) CARRY !  ( lo) SWAP ( res) !
  -1 +LOOP
  DROP ;

: COPY ( -- ) POWER TERM SIZE CELLS MOVE ;

\ : ZERO? ( result -- f )  +INDEX NIP SIZE = ;
: ZERO? ( result -- F ) SIZE CELLS 0 SKIP NIP 0= ;

0 VALUE PASS
VARIABLE EXP
VARIABLE SIGN

: DIVISOR ( -- N )
  PASS 1 = IF  5  ELSE  239  THEN ;

: ERASE 0 FILL ;

: INITIALIZE ( -- )
  POWER SIZE CELLS ERASE
  TERM  SIZE CELLS ERASE
  PASS 1 = IF  RESULT SIZE CELLS ERASE  THEN
  16  PASS DUP * / POWER !
  POWER  DIVISOR  DIVIDE
  1 EXP !  PASS 1- SIGN ! ;

0 VALUE NDIGIT

: CalcPi ( -- )
  NDIGIT 45800 U> IF
    ." Warning: digits > 45808 will be in error " CR
  THEN

  2 1+ 1
  DO
    I TO PASS
    INITIALIZE
    BEGIN
      COPY
      TERM  EXP @ DIVIDE
      SIGN @  DUP IF  SUBTRACT  ELSE  ADD  THEN
      0= SIGN !  2 EXP +!
      POWER  DIVISOR DUP *  DIVIDE
      POWER ZERO?
    UNTIL
  LOOP ;

\ VARIABLE OUT
\ : CR  CR  0 OUT ! ;
\ : #   #   1 OUT +! ;

DECIMAL
: PRINT ( -- )
  CR
  RESULT  DUP @ 0 .R  [CHAR] . EMIT CR
  NDIGIT 0
  ?DO
    0 OVER !
    DUP 10000 MULTIPLY
    DUP @  0 <# # # # # #> TYPE SPACE
\    OUT @ C/L @ > IF CR THEN  \ not needed for Camel99
    4  +LOOP
  DROP  CR ;

: GetNumber ( -- n )
  CR ." How many digits do you want? "
  PAD DUP 20 ACCEPT NUMBER? ABORT" Invalid" CR ;

: PI ( n -- ) DUP TO NDIGIT
  \ array size = ceil(ndigit / log10(2^16))
  109 UM* 525 UM/MOD SWAP ( rem) IF  1+  THEN
  ( extra for accurate last digits)
  2 +  TO SIZE

  \ create arrays in un-allocated memory
  HERE TO POWER   SIZE 20 + CELLS ALLOT
  HERE TO TERM    SIZE 20 + CELLS ALLOT
  HERE TO RESULT  SIZE 20 + CELLS ALLOT
  50 ALLOT  ( hold buffer space)
  CalcPi
  PRINT
;
\ end

 

What version of forth is it best to run on

Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429508
Share on other sites

7 minutes ago, Gary from OPA said:

You said 21 times pi. That is the 65 number. Your number is more like 6.589 times pi

Here's 6.589 times PI= 20.699953994503147648230357252429

 

I'm a little older than that. ;)

 

20.690142601946393649954889238427times PI =65

Edited by RickyDean
Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429509
Share on other sites

Currently its got specific code for Camel99 Forth. 

It is mostly ANS/Forth but with a bunch of additions to cope with TI-99. 

 

The kernel file and all the library files are here: You need is DSK1 for the system. 

CAMEL99-ITC/bin at master · bfox9900/CAMEL99-ITC · GitHub

 

The PI progRam is on DSK3. 

 

With both disks on Classic99  

Use Editor/Assembler   Option 5

file name DSK1.CAMEL99 

 

When it's loaded type INCLUDE DSK3.PI 

 

Then 100 PI  for example

 

I just tried this version (2.69) and it seems to work

 

 

Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429512
Share on other sites

8 minutes ago, RickyDean said:

Here's 6.589 times PI= 20.699953994503147648230357252429

 

I'm a little older than that. ;)

 

20.690142601946393649954889238427times PI =65

Ok I get it now. My old 54 soon to be 55 brain is running behind. You got born on pi day I got born on mother's Day, just not that it's moves back and forth so only ever 3 / 7 / 11 years does it fall right on mother's Day

  • Like 1
Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429514
Share on other sites

Just checked and most of that PI program is ANS Forth. Only the stuff at the top is for my system .

So it runs on GForth and many other compliant systems. 

 

Everything from this code and below is ANS Forth. 

DECIMAL

0 VALUE POWER  ( adr)
0 VALUE TERM   ( adr)
0 VALUE RESULT ( adr)
0 VALUE SIZE   ( n)

 

So I pasted it into GForth and this is what happened. 

OMG. Milliseconds versus 6+ minutes. 

I forgot how slow our favourite machine is.  :) 

Link to comment
https://forums.atariage.com/topic/363140-happy-pi-day-3-14/#findComment-5429549
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...