From 499f04dc4f9f864071d6ff7e75c9cbec60e2fd12 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 16 Oct 2014 19:01:26 -0700 Subject: * arith.c (gcd): Fix semantics. If either operand is zero, return the other operand. (lcm): New function. * eval.c (eval_init): Retarget registration of gcd to variable argument gcdv function. Register lcm. * lib.c (gcdv, lcmv): New functions. * lib.h (gcdv, lcm, lcmv): Declared. * txr.1: Re-document gcd with coverage of lcm. * txr.vim: Regenerated. --- lib.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib.c') diff --git a/lib.c b/lib.c index d25e47e3..4b929c97 100644 --- a/lib.c +++ b/lib.c @@ -2150,6 +2150,24 @@ val exptv(val nlist) return reduce_right(func_n2(expt), nlist, one, nil); } +val gcdv(val nlist) +{ + if (!nlist) + return zero; + if (!cdr(nlist)) + return abso(car(nlist)); + return reduce_left(func_n2(gcd), nlist, colon_k, nil); +} + +val lcmv(val nlist) +{ + if (!nlist) + return one; + if (!cdr(nlist)) + return abso(car(nlist)); + return reduce_left(func_n2(lcm), nlist, colon_k, nil); +} + val string_own(wchar_t *str) { val obj = make_obj(); -- cgit v1.2.3