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 <janneke@gnu.org>
This commit is contained in:
W. J. van der Laan 2021-04-20 13:24:27 +00:00 committed by Jan (janneke) Nieuwenhuizen
parent 2a31c8742d
commit ce80c24ae4
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* 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));

View File

@ -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 <janneke@gnu.org>
;;; Copyright © 2016,2018,2019,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;;
;;; 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"