HP Forums
(49G) Improved IEGCD for Integers - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G) Improved IEGCD for Integers (/thread-4082.html)



(49G) Improved IEGCD for Integers - Gerald H - 06-05-2015 11:43 AM

The programme is faster than the inbuilt command IEGCD but in contrast always returns a positive GCD in stack level Z.

eg For input

77
121

the programme returns

11
-3
2

Name: IZEGCD

Code:
::
  CK2&Dispatch
  # FFFF
  ::
    BINT0
    3UNROLL
    BEGIN
    ROT#1+UNROT
    DUPUNROT
    FPTR2 ^ZDIVext
    SWAP
    4UNROLLDUP
    Z0_
    EQUAL
    UNTIL
    DROP
    ZINT1_0_
    4ROLL
    ZERO_DO
    DUPUNROT
    5ROLL
    FPTR2 ^QMul
    FPTR2 ^QSub
    LOOP
    3PICK
    FPTR2 ^ZIsNeg?
    NOT?SEMI
    BINT3
    ZERO_DO
    ROT
    FPTR2 ^RNEGext
    LOOP
  ;
;