klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit cbc841acb50d97dd48757a24afcf3bbe8af39c18
parent 453c2e4a9931ec6b6ec4885138aaa8e1f11b8b31
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sun, 10 Apr 2011 22:11:28 -0300

Added support for bigints to max and min applicatives.

Diffstat:
Msrc/kgnumbers.c | 22++++------------------
Msrc/kinteger.c | 3++-
2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -718,36 +718,22 @@ void kmin_max(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) &dummy); TValue res; - bool one_finite = false; - TValue break_val; + if (minp) { res = KEPINF; - break_val = KEMINF; /* min possible number */ } else { res = KEMINF; - break_val = KEPINF; /* max possible number */ } TValue tail = ptree; + bool (*cmp)(TValue, TValue) = minp? knum_ltp : knum_gtp; + while(pairs--) { TValue first = kcar(tail); tail = kcdr(tail); - if (ttiseinf(first)) { - if (tv_equal(first, break_val)) { - res = first; - break; - } - } else if (!one_finite) { + if ((*cmp)(first, res)) res = first; - one_finite = true; - } else if (minp) { - if (ivalue(first) < ivalue(res)) - res = first; - } else { /* maxp */ - if (ivalue(first) > ivalue(res)) - res = first; - } } kapply_cc(K, res); } diff --git a/src/kinteger.c b/src/kinteger.c @@ -277,7 +277,8 @@ bool kbigint_negativep(TValue tv_bigint) /* unlike the positive? applicative this would return true on zero, but zero is never represented as a bigint so there is no problem */ -/* XXX: but bigints constructed from fixints could be, clean this up */ +/* Bigints constructed from fixints could be, but we don't care about + zero returning positive in other place than in positive? */ bool kbigint_positivep(TValue tv_bigint) { return kbigint_posp(tv2bigint(tv_bigint));