(49G & 50g) Faster GCD for Integers

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G & 50g) Faster GCD for Integers (/thread-9312.html)



(49G & 50g) Faster GCD for Integers - Gerald H - 10-18-2017 06:58 AM

For input two integers the programme returns the GCF, the programme is faster for integers of size (Edit: 1194 hex digits, ie 4500 dec digits) & greater, for smaller input the programme uses the inbuilt GCD.

A slightly improved programme for the 49G, crossover point is now for input of over 2000 digits.

The programme is good for the 50g, cross over point should be changed to 4000 digits.


Size: 191.0000

CkSum: # 951Ah (# 6597h for 50g version)

Code:
::
  CK2&Dispatch
  # FFFF
  ::
    2DUP
    FPTR2 ^ZNMin
    LENHXS
    # 7D0  (or # FA0 on the 50g)
    #<case
    FPTR2 ^ZGCDext
    FPTR2 ^ZAbs
    SWAP
    FPTR2 ^ZAbs
    2DUP
    Z<
    ?SWAP
    FPTR2 ^DupQIsZero?
    caseDROP
    DUPUNROT
    FPTR2 ^ZMod
    FPTR2 ^DupQIsZero?
    caseDROP
    SWAP
    FPTR2 ^ZTrialDiv2
    ROT
    FPTR2 ^ZTrialDiv2
    ROT
    #MIN
    3UNROLL
    BEGIN
    2DUP
    FPTR2 ^RSUBext
    FPTR2 ^ZTrialDiv2
    #0<>
    WHILE
    ::
      FPTR2 ^DupZIsNeg?
      case
      ::
        SWAPDROP
        FPTR2 ^ZAbs
      ;
      ROTDROP
    ;
    REPEAT
    2DROP
    ZINT 2
    ROT
    FPTR2 ^RP#
    FPTR2 ^RMULText
  ;
;