Gerson's Pi Program
|
03-11-2022, 12:42 PM
(This post was last modified: 03-11-2022 01:38 PM by EdS2.)
Post: #20
|
|||
|
|||
RE: Gerson's Pi Program
Indeed I do like a pi program, and a spigot program, and anything multiprecision.
About porting to BBC Basic - in the case of your spigot, a very naive initial port would produce 50 digits in 118 seconds. With a change to integer variables, it becomes 66 seconds, and then by changing / to DIV, it becomes 54 seconds. We can even save another second by setting D% to 10 and using that instead of the literal in a couple of places. So by recoding in the fastest idiom for BBC Basic, we get a 2x speedup. (The above timings are for Basic 2 on a 2MHz 6502 - later Basics were faster, and of course CPU clock speeds also improved.) Other changes which can be beneficial: - using only single-letter variables, especially A% to Z% which are special-cased - removing the loop variable from NEXT - using FOR, REPEAT, PROC and FN instead of line numbers - inlining functions and subroutines - removing blank spaces and consolidating multiple lines Of course, some of these re-codings make the program a bit less clear, and one gets diminishing returns. It's a pity that all the % signs for integer variables are a bit ugly especially if you're not used to them: BBC Basic has no DEF INT. In the case of Gerson's program, the version below produces 12 digits in 14 seconds, compared to 43 seconds for the initial port. This version produces 36 digits in 186s. (Edit: and 100 digits in 2510s.) I was quite pleased to do without both FN definitions and especially the 5E-6 which I didn't understand or feel comfortable with. I could use DIV and MOD in a natural way. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)