klisp

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

commit 4fd4c887b6b86334c41366a833864401ef84fc11
parent 72f839f5a13fd5f05a86517fa4e4ebf205831968
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sun, 15 May 2011 11:42:40 -0300

Added inexact integer support for odd? & even?.

Diffstat:
Msrc/kgnumbers.c | 8+++++---
Msrc/kreal.c | 4++--
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -1248,7 +1248,7 @@ bool knegativep(klisp_State *K, TValue n) } } -/* n is finite */ +/* n is finite, integer */ bool koddp(TValue n) { switch (ttype(n)) { @@ -1256,8 +1256,9 @@ bool koddp(TValue n) return (ivalue(n) & 1) != 0; case K_TBIGINT: return kbigint_oddp(n); + case K_TDOUBLE: + return fmod(dvalue(n), 2.0) != 0.0; default: - /* shouldn't happen */ assert(0); return false; } @@ -1270,8 +1271,9 @@ bool kevenp(TValue n) return (ivalue(n) & 1) == 0; case K_TBIGINT: return kbigint_evenp(n); + case K_TDOUBLE: + return fmod(dvalue(n), 2.0) == 0.0; default: - /* shouldn't happen */ assert(0); return false; } diff --git a/src/kreal.c b/src/kreal.c @@ -660,7 +660,7 @@ void kdouble_print_string(klisp_State *K, TValue tv_double, double kdouble_div_mod(double n, double d, double *res_mod) { double div = floor(n / d); - double mod = n - div * d; + double mod = fmod(n, d); /* div, mod or div-and-mod */ /* 0 <= mod0 < |d| */ @@ -680,7 +680,7 @@ double kdouble_div_mod(double n, double d, double *res_mod) double kdouble_div0_mod0(double n, double d, double *res_mod) { double div = floor(n / d); - double mod = n - div * d; + double mod = fmod(n, d); /* div0, mod0 or div-and-mod0 */ /*