(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 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(50g) Convert Approximate to Exact for given argument - DavidM - 08-02-2021 12:28 AM
RE: (50g) Convert Approximate to Exact for given argument - johnb - 02-05-2024, 01:21 AM
|
User(s) browsing this thread: 2 Guest(s)