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:
parent
2a31c8742d
commit
ce80c24ae4
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* 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.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -177,7 +178,7 @@ multiply (SCM x) ///((name . "*") (arity . n))
|
||||||
SCM
|
SCM
|
||||||
logand (SCM x) ///((arity . n))
|
logand (SCM x) ///((arity . n))
|
||||||
{
|
{
|
||||||
long n = 0;
|
long n = -1;
|
||||||
while (x != cell_nil)
|
while (x != cell_nil)
|
||||||
{
|
{
|
||||||
assert_number ("multiply", CAR (x));
|
assert_number ("multiply", CAR (x));
|
||||||
|
|
|
@ -6,7 +6,7 @@ exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests
|
||||||
;;; -*-scheme-*-
|
;;; -*-scheme-*-
|
||||||
|
|
||||||
;;; GNU Mes --- Maxwell Equations of Software
|
;;; 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.
|
;;; 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 "remainder" 2 (remainder 11 3))
|
||||||
(pass-if-equal "modulo" 2 (modulo 11 3))
|
(pass-if-equal "modulo" 2 (modulo 11 3))
|
||||||
(pass-if-equal "expt" 8 (expt 2 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 "logior" 7 (logior 0 1 2 4))
|
||||||
(pass-if-equal "logxor" -2 (logxor 1 -1))
|
(pass-if-equal "logxor" -2 (logxor 1 -1))
|
||||||
(pass-if-equal "ash"
|
(pass-if-equal "ash"
|
||||||
|
|
Loading…
Reference in a new issue