klisp

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

commit 68d4ef952a9f2cf074189b309fd52ce2126d8001
parent bf840103262c57f0cf81fe4fcf641fb67f43bc48
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sun, 10 Apr 2011 21:58:25 -0300

Refactored knum_lep, knum_gtp and knum_gep to use knum_ltp.

Diffstat:
Msrc/kgnumbers.c | 64+++-------------------------------------------------------------
1 file changed, 3 insertions(+), 61 deletions(-)

diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -84,8 +84,6 @@ bool knum_eqp(TValue n1, TValue n2) } } -/* REFACTOR: could be just ltp and all other as calls to it - cf: kbigint_ltp, ... */ bool knum_ltp(TValue n1, TValue n2) { switch(max_ttype(n1, n2)) { @@ -106,65 +104,9 @@ bool knum_ltp(TValue n1, TValue n2) } } -bool knum_lep(TValue n1, TValue n2) -{ - switch(max_ttype(n1, n2)) { - case K_TFIXINT: - return ivalue(n1) <= ivalue(n2); - case K_TBIGINT: { - kensure_bigint(n1); - kensure_bigint(n2); - return kbigint_lep(n1, n2); - } - case K_TEINF: - return tv_equal(n1, n2) || tv_equal(n1, KEMINF) || - tv_equal(n2, KEPINF); - default: - /* shouldn't happen */ - assert(0); - return false; - } -} - -bool knum_gtp(TValue n1, TValue n2) -{ - switch(max_ttype(n1, n2)) { - case K_TFIXINT: - return ivalue(n1) > ivalue(n2); - case K_TBIGINT: { - kensure_bigint(n1); - kensure_bigint(n2); - return kbigint_gtp(n1, n2); - } - case K_TEINF: - return !tv_equal(n1, n2) && (tv_equal(n1, KEPINF) || - tv_equal(n2, KEMINF)); - default: - /* shouldn't happen */ - assert(0); - return false; - } -} - -bool knum_gep(TValue n1, TValue n2) -{ - switch(max_ttype(n1, n2)) { - case K_TFIXINT: - return ivalue(n1) >= ivalue(n2); - case K_TBIGINT: { - kensure_bigint(n1); - kensure_bigint(n2); - return kbigint_ltp(n1, n2); - } - case K_TEINF: - return tv_equal(n1, n2) || tv_equal(n1, KEPINF) || - tv_equal(n2, KEMINF); - default: - /* shouldn't happen */ - assert(0); - return false; - } -} +bool knum_lep(TValue n1, TValue n2) { return !knum_ltp(n2, n1); } +bool knum_gtp(TValue n1, TValue n2) { return knum_ltp(n2, n1); } +bool knum_gep(TValue n1, TValue n2) { return !knum_ltp(n1, n2); } /* ** REFACTOR: all of *, -, and + should be refactored