50G fraction question Q-> function max denominator
|
11-08-2019, 05:54 PM
Post: #13
|
|||
|
|||
RE: 50G fraction question Q-> function max denominator
Here's one last take on the "closest fraction with power-of-2 denominator" concept.
This one uses a SysRPL implementation, and instead of requiring the maximum denominator as a given argument, that value is obtained from a global variable named "MxDen". If that variable isn't found in the current path, a new one containing a default value of 64 is created for subsequent use. As such, there is only one argument required for this program: a value to be converted (either numeric or symbolic). The final result depends on which type is given as well as the value of MxDen. When I was playing around with this, I realized that I often wanted to go back-and-forth between the symbolic and real/approximate representations of some value. So this version evolved to function as a "toggler" between those two forms. If given a real/approximate number, it is converted to the nearest rational form. If given a symbolic, it is converted to the nearest real form. In both cases, the result is based on the currently specified maximum denominator. This means that if you give the program an argument of π with a max denominator of 64, the result will be a decimal representation of the nearest "power of 2" rational that approximates π in that range (3+9/64): 3.140625. An exact integer is treated the same as a symbolic value; the result will be that same integer in approximate form. The source code below is appropriate for the 50g's on-board MASD compiler (ASM from menu 256), and assumes you have the HP extable installed: Code: !NO CODE After compiling, store the code into a named variable (I call mine "Imp" for "Imperial") and you're all set! A zipped pre-compiled version is also attached. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)