Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mailrus!hellgate.utah.edu!ug.utah.edu!efinley From: efinley%ug.utah.edu@cs.utah.edu (Elliott Finley) Newsgroups: comp.sys.handhelds Subject: a better ->Qpi Keywords: hp28s hp48sx Message-ID: <1990Mar14.221340.2764@hellgate.utah.edu> Date: 15 Mar 90 05:13:40 GMT Organization: University of Utah CS Dept Lines: 45 When I tried using the built in '->Qpi' function of the hp48sx, I was a little disappointed. For a simple example of what I mean, try entering '1/3*pi', change it to a number, then execute '->Qpi'. It gives you a big fraction that is supposed to be a "best guess". Here are three programs that I use that will correctly factor pi out of a fraction. They'll also work on a 28 with one change (see below). Most of the code in the R-QC program was taken from an article that appeared on the net a while back, I can't remember who posted it so I can't give credit where credit is due. (Thanks, whoever it was) %%HP: T(3)A(D)F(.); @ R->Q (this works the same as the built in '->Q')@ \<< EVAL \->NUM R\->QC \-> RN RD \<< "'" RN ABS \->STR + "/" + RD \->STR + "'" + OBJ\-> RN SIGN * \>> \>> %%HP: T(3)A(D)F(.); @ R->QP (this is the replacement for the built in '->Qpi')@ \<< EVAL \->NUM DUP \pi \->NUM / \-> R P \<< R R\->QC P R\->QC \-> RN RD PN PD \<< IF PD RD < THEN PN \pi * PD / ELSE "'" RN ABS \->STR + "/" + RD \->STR + "'" + OBJ\-> RN SIGN * END \>> \>> \>> To use the above program on a 28 just change the OBJ-> to STR-> %%HP: T(3)A(D)F(.); @ R->QC (this program is called from the other two)@ \<< .000000000005 1 0 \-> X P A B \<< X WHILE 'ABS(FLOOR(X*A+.5)-X*A)\>=P*A' EVAL REPEAT INV DUP IP ABS A * B + A 'B' STO 'A' STO FP END DROP 'FLOOR(X*A+.5)' EVAL A \>> \>> Elliot