Jump to content
IGNORED

Calculate Pi number on your Colecovision with CVBasic


Recommended Posts

Hi all.

 

Today is Pi day (03/14) so here is a little CVBasic program to calculate it in your Colecovision.

 

Enjoy it!

 

	REM
	REM Calculate digits of Pi
	REM by Oscar Toledo G. http://nanochess.org/
	REM Creation date: 3/14/16 (Mar/14/2016)
        REM Revision date: 3/14/24 (Mar/14/2024) for CVBasic.

	REM Based on http://www.codecodex.com/wiki/Calculate_digits_of_pi#C

	CONST scale = 100
	CONST arrinit = 20
	CONST #digits = 250	' It will generate 250/14*2 digits
				' Cannot be greater because arr is 8-bit
	DIM arr(#digits + 1)

	carry = 0
	FOR #i = 0 TO #digits
		arr(#i) = arrinit
	NEXT #i

	PRINT AT 0,"Digits of PI"
        PRINT AT 72,""
	#i = #digits
	WHILE 1
		#sum = 0
		FOR j = #i TO 1 STEP -1
			#sum = #sum * j + scale * arr(j)
			arr(j) = #sum % (j * 2 - 1)
			#sum = #sum / (j * 2 - 1)
		NEXT j
		k = carry + #sum / scale
		PRINT k / 10
		IF #i = #digits THEN PRINT "."
		PRINT k % 10
		carry = #sum % scale
		IF #i < 14 THEN EXIT WHILE
		#i = #i - 14
	WEND

	WHILE 1
	WEND

 

CapturadePantalla2024-03-14ala(s)11_25_18.thumb.png.a53454244d81dbc57614f8e2ca53d8b3.png

pi.bas pi.rom

  • Like 4
Link to comment
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...