(50g) Convert Approximate to Exact for given argument
|
08-02-2021, 12:28 AM
Post: #1
|
|||
|
|||
(50g) Convert Approximate to Exact for given argument
Except for those rare occasions that I actually need to do something symbolic on my 50g, I usually have it in approximate mode. As a result, I am occasionally frustrated that I've inadvertently changed a program, list, algebraic or other object into something containing approximate numbers (reals), when it was originally intended to have contained integers. It's usually not a huge deal to change the mode and repeat whatever action is needed to obtain the desired result, but I recently decided to put together a program to do the honors instead.
The System RPL program below attempts to seek out approximate numbers contained in the object in stack level 1, and converts those which have no fractional part to an exact integer. The program contains a main procedure that is called recursively on the object whenever a composite is encountered. Most objects that it encounters along the way aren't approximate numbers, so those are simply ignored and left alone. The program considers the following objects as composites that may contain nested items, and thus "explodes" these for further processing when encountered: - Lists - Secondaries (programs) - Symbolics (algebraics) - Arrays (real and matrix, but not complex or linked arrays) - Tagged objects As an example, if you enter '(3*X^2+1)/19.2' on the command line while in approximate mode on a 50g, it treats all of the numbers as approximate numbers and compiles the entry as '(3.*X^2.+1.)/19.2'. Executing this program with that input will result in all of the approximate numbers that represent integers being converted to exact integers: '(3*X^2+1)/19.2'. While I recognize that this is essentially an aid to fix my own screwups, I'm hoping that others might find a use for it as well. The following is compilable on a 50g with the standard extable installed: Code: !NO CODE |
|||
02-05-2024, 01:21 AM
Post: #2
|
|||
|
|||
RE: (50g) Convert Approximate to Exact for given argument
(08-02-2021 12:28 AM)DavidM Wrote: As a result, I am occasionally frustrated that I've inadvertently changed a program, list, algebraic or other object into something containing approximate numbers (reals), when it was originally intended to have contained integers. Sorry I am so late to this party, but hopefully someone will find the following advice useful. Having been a heavy user of an HP-48g the past couple years, I've been frustrated with accidentally clobbering a program or variable here and there. I've learned a trick:
(Legend: above, underlined are literal directory names, placeholder for names are in italic.) Topics are general packages of components. For example, I might have topics "CS", "NUMR" (numerical recipes/solutions), "INTV" (interval arithmetic), "PROJ1" and "PROJ2" (two short-term work projects). By always working in a {work} directory, I can accidently override a global or package variable with one of my own... but I cannot accidentally overwrite one, permanently clobbering it. I just purge the offending item from {work} and try again. And then, it's also easy to clean up after myself. I can safely purge the entire contents of my "workspace" without clobbering any of the components I'll be wanting to use there for next time. This strategy should work for all RPL calculator series: 28, 48, 49 (all variants), and 50. Hope this helps! Daily drivers: 15c, 32sII, 35s, 41cx, 48g, WP 34s/31s. Favorite: 16c. Latest: 15ce, 48s, 50g. Gateway drug: 28s found in yard sale ~2009. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)