(11C) GCD and LCM
|
01-07-2018, 06:00 PM
(This post was last modified: 01-07-2018 06:05 PM by Dieter.)
Post: #5
|
|||
|
|||
RE: (11C) Least Common Multiple <> GCD
(01-07-2018 08:26 AM)wawa Wrote: it is because I use the rule gcd(a,b)=gcd(b,a mod b) which decreases faster than gcd(a,b)=gcd(b,a-b). @Gamo: That's the same algorithm as proposed in my reply to your 12C program. @wawa: I would recommend changing the last steps to avoid results ≥ 1 E+10 when a*b is calculated: Code: 22 R↓ Yes, it's really sad that a MOD function was not implemented on the Voyagers, not even on the 15C. A better way than coding a mod b as b*frac(a/b) is a–b*int(a/b). This avoids roundoff errors that have to be corrected by the RND command in your program. But it is a bit more tricky to implement, especially if only the stack is used. However, with direct stack access and a MOD function a GCD routine can be done in merely six steps, e.g. on the HP41: Code: 01 LBL 01 :-) Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(11C) GCD and LCM - Gamo - 01-06-2018, 12:59 PM
RE: (11C) Least Common Multiple <> GCD - wawa - 01-06-2018, 04:34 PM
RE: (11C) Least Common Multiple <> GCD - Gamo - 01-07-2018, 01:09 AM
RE: (11C) Least Common Multiple <> GCD - wawa - 01-07-2018, 08:26 AM
RE: (11C) Least Common Multiple <> GCD - Dieter - 01-07-2018 06:00 PM
RE: (11C) Least Common Multiple <> GCD - Csaba Tizedes - 01-07-2018, 09:09 PM
RE: (11C) Least Common Multiple <> GCD - wawa - 01-08-2018, 12:29 PM
|
User(s) browsing this thread: 1 Guest(s)