Christian Berthold Karl Schroeder (cschroed@uoguelph.ca) wrote: > Hi folks. I have a questions. I'm writing a couple of little > routines to handle fractions symbolically. One enters the args as > 2: `1/2' > 1: `3/4' > and then hits add. 1,2,3, and 4 are stored as a,b,c, and d > respectivly. For adding then, the program goes > a d * b c * + `f' STO b d * `g' STO > Now here comes the problem... I want the answer to be in algebraic > type, the same as the arguments. I can't just put `f/g' because of > course, that causes the quotient of f and g to be returned. I'd like > the result to be retured in the form > 1: `10/8' > any ideas? > Oh yeah, HP48SX is being used. Paul Stabnow and Jack Levy replied, suggesting that ->Q be used. Although this works, and is the best solution when a very short program is your goal, it is very slow and can introduce roundoff errors. Jack went on to suggest embedding it into a string and then using OBJ-> to turn it back into an algebraic. This never introduces errors, but is also rather slow. There are three methods not yet mentioned. (1) The MATCH commands can be used here. They can turn the algebraic 'f/g' into '10/8' by doing a pattern match. The MATCH commands are explained in your SX owner's manual. I do not recommend this method, however, because it's *very* slow. (2) Another method is to call the unsupported but stable entry point which does exactly what you want: #5603Eh SYSEVAL Try it: put 10 and 8 on the stack, then CAREFULLY type the above line and press ENTER. Cool, huh? Fast, too. Caution!!! ONLY use this SYSEVAL when you're SURE that two real numbers are on the stack!!! Failure to do would be a Bad Thing. Running it with too few arguments on the stack will almost certainly crash your HP48. You may feel confident using this in a program, however, since the program can make sure that two numbers are on the stack, and since it not only works in every version of the SX but the GX as well, and HP even used it in a posting to comp.sys.handhelds on April 2, 1991 (see NEW2Q.TXT on Goodies Disk #3), so I guess it's sorta semi-supported. (3) If you like the speed of System RPL but you cannot risk using unsupported entry points, here's a little program that does the same thing as the previous method but it uses only supported entry points: << { / } 1 GET 3 #18C34h SYSEVAL #546Dh SYSEVAL >> This little goody actually runs faster than the previous single SYSEVAL; it uses 100% supported entry points; and it has the very nice benefit of erroring politely if there are too few arguments on the stack (rather than just crashing, which method #2 can do). But it does NOT check argument type, so be careful only to use it on things that can be in 'a/b' form (real numbers, or symbolics, or complex numbers, or units, or most combinations of these). -Joe Horn- "I didn't do it, nobody saw me, you can't prove anything." -- Bart