From ce80c24ae4ad86619efb46c726b59a3260cdf1ee Mon Sep 17 00:00:00 2001 From: "W. J. van der Laan" Date: Tue, 20 Apr 2021 13:24:27 +0000 Subject: [PATCH] mes: Make logand work correctly. * src/math.c (logand): Start from -1 instead of 0, so that the bitwise AND-ed result is the intersection of bit sets instead of always 0. * tests/math.test ("logand", "logand 3"): Test it. Co-authored-by: Jan (janneke) Nieuwenhuizen --- src/math.c | 3 ++- tests/math.test | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/math.c b/src/math.c index 390707f8..30dcf36a 100644 --- a/src/math.c +++ b/src/math.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -177,7 +178,7 @@ multiply (SCM x) ///((name . "*") (arity . n)) SCM logand (SCM x) ///((arity . n)) { - long n = 0; + long n = -1; while (x != cell_nil) { assert_number ("multiply", CAR (x)); diff --git a/tests/math.test b/tests/math.test index 157b55e5..b5fe7f14 100755 --- a/tests/math.test +++ b/tests/math.test @@ -6,7 +6,7 @@ exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests ;;; -*-scheme-*- ;;; GNU Mes --- Maxwell Equations of Software -;;; Copyright © 2016,2018,2019 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2016,2018,2019,2021 Jan (janneke) Nieuwenhuizen ;;; ;;; This file is part of GNU Mes. ;;; @@ -41,6 +41,8 @@ exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests (pass-if-equal "remainder" 2 (remainder 11 3)) (pass-if-equal "modulo" 2 (modulo 11 3)) (pass-if-equal "expt" 8 (expt 2 3)) +(pass-if-equal "logand" -1 (logand)) +(pass-if-equal "logand 3" 3 (logand 3 7 11)) (pass-if-equal "logior" 7 (logior 0 1 2 4)) (pass-if-equal "logxor" -2 (logxor 1 -1)) (pass-if-equal "ash"