klisp

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

commit 18b393353aeaf7d8168c78872f87830156ec4109
parent 5946d56ba87fa862d03fbc0bb50035a236ece2eb
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 12 Apr 2011 20:40:01 -0300

Bugfix: (abs INT32_MIN) was INT32_MIN, added check to kabs to use bigints in that case.

Diffstat:
Msrc/kgnumbers.c | 11+++++++++--
Msrc/kground.c | 2+-
Msrc/kinteger.h | 1+
3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -637,10 +637,17 @@ void kabs(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) switch(ttype(n)) { case K_TFIXINT: { int32_t i = ivalue(n); - kapply_cc(K, i < 0? i2tv(-i) : n); - return; + if (i != INT32_MIN) { + kapply_cc(K, i < 0? i2tv(-i) : n); + return; + } /* if i == INT32_MIN, fall through */ + /* MAYBE: we could cache the bigint INT32_MAX+1 */ } case K_TBIGINT: { + /* this is needed for INT32_MIN, can't be in previous + case because it should be in the same block, remember + the bigint is allocated on the stack. */ + kensure_bigint(n); kapply_cc(K, kbigint_abs(K, n)); return; } diff --git a/src/kground.c b/src/kground.c @@ -704,7 +704,7 @@ void kinit_ground_env(klisp_State *K) add_applicative(K, ground_env, "min", kmin_max, 2, symbol, b2tv(FMIN)); add_applicative(K, ground_env, "max", kmin_max, 2, symbol, b2tv(FMAX)); - /* 12.5.14 gcm, lcm */ + /* 12.5.14 gcd, lcm */ add_applicative(K, ground_env, "gcd", kgcd, 0); add_applicative(K, ground_env, "lcm", klcm, 0); diff --git a/src/kinteger.h b/src/kinteger.h @@ -86,6 +86,7 @@ bool kbigint_gep(TValue bigint1, TValue bigint2); TValue kbigint_plus(klisp_State *K, TValue n1, TValue n2); TValue kbigint_times(klisp_State *K, TValue n1, TValue n2); TValue kbigint_minus(klisp_State *K, TValue n1, TValue n2); + TValue kbigint_div_mod(klisp_State *K, TValue n1, TValue n2, TValue *res_r); TValue kbigint_div0_mod0(klisp_State *K, TValue n1, TValue n2, TValue *res_r);