1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
22 greater_p (SCM x) ///((name . ">") (arity . n))
27 assert (TYPE (car (x)) == NUMBER);
28 if (VALUE (car (x)) >= n) return cell_f;
36 less_p (SCM x) ///((name . "<") (arity . n))
41 assert (TYPE (car (x)) == NUMBER);
42 if (VALUE (car (x)) <= n) return cell_f;
50 is_p (SCM x) ///((name . "=") (arity . n))
52 if (x == cell_nil) return cell_t;
53 assert (TYPE (car (x)) == NUMBER);
54 int n = VALUE (car (x));
58 if (VALUE (car (x)) != n) return cell_f;
65 minus (SCM x) ///((name . "-") (arity . n))
68 assert (TYPE (a) == NUMBER);
75 assert (TYPE (car (x)) == NUMBER);
79 return make_number (n);
83 plus (SCM x) ///((name . "+") (arity . n))
88 assert (TYPE (car (x)) == NUMBER);
92 return make_number (n);
96 divide (SCM x) ///((name . "/") (arity . n))
100 assert (TYPE (car (x)) == NUMBER);
104 while (x != cell_nil)
106 assert (TYPE (car (x)) == NUMBER);
107 n /= VALUE (car (x));
110 return make_number (n);
114 modulo (SCM a, SCM b)
116 assert (TYPE (a) == NUMBER);
117 assert (TYPE (b) == NUMBER);
118 return make_number (VALUE (a) % VALUE (b));
122 multiply (SCM x) ///((name . "*") (arity . n))
125 while (x != cell_nil)
127 assert (TYPE (car (x)) == NUMBER);
128 n *= VALUE (car (x));
131 return make_number (n);
135 logior (SCM x) ///((arity . n))
138 while (x != cell_nil)
140 assert (TYPE (car (x)) == NUMBER);
141 n |= VALUE (car (x));
144 return make_number (n);
148 ash (SCM n, SCM count)
150 assert (TYPE (n) == NUMBER);
151 assert (TYPE (count) == NUMBER);
153 int ccount = VALUE (count);
154 return make_number ((ccount < 0) ? cn >> -ccount : cn << ccount);