(42S) GCF
|
07-10-2016, 04:41 AM
(This post was last modified: 06-15-2017 01:48 PM by Gene.)
Post: #1
|
|||
|
|||
(42S) GCF
Prompted by Eddie W Shore's
http://www.hpmuseum.org/forum/thread-6528.html here's my short GCD programme. The prog takes X & Y values from stack & returns GCD , or GCF if you wish, to stack level X. Code:
|
|||
07-10-2016, 07:21 AM
Post: #2
|
|||
|
|||
RE: HP 42S: GCF
Same as mine, except I have a "+" in step 8 (since you know X contains zero).
I also add Smallest Common Multiple: *LBL "SCM" RCL ST Y RCL ST Y XEQ 00 / x RTN Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
07-10-2016, 08:41 PM
Post: #3
|
|||
|
|||
RE: HP 42S: GCF
Is this ABS necessary?
Günter |
|||
07-11-2016, 04:26 AM
Post: #4
|
|||
|
|||
RE: HP 42S: GCF
Yes, ABS is needed for some negative inputs, otherwise the GCD is returned as a negative which is surely not the GREATEST common factor.
|
|||
07-11-2016, 09:15 AM
Post: #5
|
|||
|
|||
RE: HP 42S: GCF | |||
07-11-2016, 10:01 AM
Post: #6
|
|||
|
|||
RE: HP 42S: GCF
Look at your own code ;-)
it does GCF, I keep them both in 1 program. Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
07-11-2016, 06:58 PM
(This post was last modified: 07-11-2016 07:11 PM by Dieter.)
Post: #7
|
|||
|
|||
RE: HP 42S: GCF
(07-10-2016 04:41 AM)Gerald H Wrote: here's my short GCD programme. Fine – my fractions programs used virtually the same code, but with a final + instead of R↓ which works as a DROP here. ;-) FTR, here is an alternate GCD routine with a slightly shorter and thus faster loop. It can be used if Z does not have to be preserved: Code: 01 LBL 00 And finally a solution that returns both LCM and GCD (in Y resp. X): Code: 01 LBL"LCMGCD" This is HP41 code. HP42s users may imagine an additional "ST" in the stack related commands. ;-) Dieter |
|||
07-12-2016, 04:46 AM
Post: #8
|
|||
|
|||
RE: HP 42S: GCF
(07-11-2016 06:58 PM)Dieter Wrote:(07-10-2016 04:41 AM)Gerald H Wrote: here's my short GCD programme. I tried the first programme but for various inputs it returned 1. |
|||
07-12-2016, 04:59 AM
Post: #9
|
|||
|
|||
RE: HP 42S: GCF
Sorry, my error, I entered STO "Z" for STO ST Z.
Now functions correctly. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 7 Guest(s)