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
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
;
;