From 007ee2a4d8f3b87779599f06512973c92d0640e8 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Tue, 20 Dec 2016 07:50:27 +1300 Subject: [PATCH] Implemented fix:gcd. --- src/scheme-primitives.4th | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/scheme-primitives.4th b/src/scheme-primitives.4th index 5ec154b..7e123f7 100644 --- a/src/scheme-primitives.4th +++ b/src/scheme-primitives.4th @@ -223,12 +223,27 @@ swap abs swap ; 1 make-fa-primitive fix:abs +: sort-pair + 2dup > if + swap + then +; ( Find the GCD of n1 and n2 where n2 < n1. ) : gcd ( n1 n2 -- m ) - + sort-pair + over 0= if + swap drop + else + over mod + recurse + then ; +:noname ( fixnum fixnum -- fixnum' ) + drop swap drop gcd fixnum-type +; 2 make-fa-primitive fix:gcd + \ --- Flonums --- :noname ( flonum flonum -- bool ) -- 2.20.1