From 4175579d08b2a7fdde46dfbe1fe5d0a864cfda61 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 27 Aug 2017 12:53:01 +0200 Subject: [PATCH] core: Add logand, lognot. * src/math.c (logand, lognot): New function. --- src/math.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/math.c b/src/math.c index c0b6190b..1e9df4da 100644 --- a/src/math.c +++ b/src/math.c @@ -135,6 +135,19 @@ multiply (SCM x) ///((name . "*") (arity . n)) return MAKE_NUMBER (n); } +SCM +logand (SCM x) ///((arity . n)) +{ + int n = 0; + while (x != cell_nil) + { + assert (TYPE (car (x)) == TNUMBER); + n &= VALUE (car (x)); + x = cdr (x); + } + return MAKE_NUMBER (n); +} + SCM logior (SCM x) ///((arity . n)) { @@ -148,6 +161,14 @@ logior (SCM x) ///((arity . n)) return MAKE_NUMBER (n); } +SCM +lognot (SCM x) +{ + assert (TYPE (x) == TNUMBER); + int n = ~VALUE (x); + return MAKE_NUMBER (n); +} + SCM ash (SCM n, SCM count) {