Path: utzoo!attcan!uunet!mcsun!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!caen!sdd.hp.com!spool.mu.edu!news.cs.indiana.edu!msi.umn.edu!noc.MR.NET!gacvx2.gac.edu!hhdist From: NORM%IONAACAD.BITNET@CUNYVM.CUNY.EDU (Norman Walsh) Newsgroups: comp.sys.handhelds Subject: RE: HP48: GCF and LCD programs Message-ID: <5E61BBE10000251E@gacvx2.gac.edu> Date: 1 Mar 91 20:51:00 GMT Lines: 46 Return-path: <@CUNYVM.CUNY.EDU:NORM@IONAACAD.BITNET> In-reply-to: Your message of Fri 1 Mar 1991 13:32 CST To: handhelds@gac.edu, eagle@catt.ncsu.edu >I'm having trouble translating a program to RPN. It's a very useful >program that I used in my Casio fx-4000P. It calculates the greatest >common factor between two numbers. > (text deleted) >the GCF program into RPN, here it is in some pseudocode form: > >input a;a=abs(a); >input b;b=abs(b); >if (a swap(a,b); >repeat >{ > c=-(int(a/b)*b-a); > a=b; > b=c; >} until c=0; >print b; Daniel, Here is my translation of your psuedocode. It is not particularly efficient because I have endeavored to duplicate the psuedocode above as closely as possible. 'a' and 'b' are taken from the stack, 'a' is returned (not 'b' as the code above would have us believe): << 0 -> a b c << IF a b < THEN a b 'a' STO 'b' STO END DO a b / IP b * a - NEG DUP 'c' STO b 'a' STO 'b' STO UNTIL c 0 == END a >> >> I have taken the slight liberty of optimizing the storage of b into a and c into b by duping the result of calculating the new 'c' on the stack and storing that into b rather than recalling it from 'c' and storing it in 'b'. If there is any part of the above code you would like explained, just let me know. 'though I'll be away next week so be patient... ndw