Pi digits (again) - an unbounded spigot program
|
05-17-2024, 04:58 PM
(This post was last modified: 05-17-2024 05:01 PM by John Keith.)
Post: #13
|
|||
|
|||
RE: Pi digits (again) - an unbounded spigot program
(05-12-2024 08:57 PM)EdS2 Wrote: ... this on the other hand is Gibbons' unbounded spigot. Different, in some sense, except that we don't have bignums here. We do if we are using the HP 49/50 or Prime. The spigot programs use only integer math and thus do not require arbitrary-precision floating-point software, making them a good fit for the newer HP's. Here is a straightforward RPL implementation. The program stores the digits in a string for convenience but could be easily adapted to display each digit if desired. Given an integer s on the stack, the program will return approximately 0.3*s digits. This is because only about 1 in 4 iterations actually return a new digit. Code:
If we assume that the conjecture in section 6 of Gibbons' paper is correct, we can use the last program in the paper called 'piG3' which is much more efficient. Not only does it return a new digit for every iteration, it also has features that make the program run faster. It only requires one integer divide per digit, and those are slow in RPL. Also, since there is no test clause, the control structure is simpler and we can replace the WHILE loop with a FOR loop which is faster. Here, then, is an RPL implementation of 'piG3'. It runs about 7 times faster than the previous program and is about 100 bytes smaller. Given an integer on the stack, the program will return that many digits. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)