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/>.
23 // greater_p (SCM x) ///((name . ">") (arity . n))
26 // while (x != cell_nil)
28 // assert (TYPE (car (x)) == TNUMBER);
29 // if (VALUE (car (x)) >= n) return cell_f;
30 // n = VALUE (car (x));
37 // less_p (SCM x) ///((name . "<") (arity . n))
40 // while (x != cell_nil)
42 // assert (TYPE (car (x)) == TNUMBER);
43 // if (VALUE (car (x)) <= n) return cell_f;
44 // n = VALUE (car (x));
51 is_p (SCM x) ///((name . "=") (arity . n))
53 if (x == cell_nil) return cell_t;
54 assert (TYPE (car (x)) == TNUMBER);
55 int n = VALUE (car (x));
59 if (VALUE (car (x)) != n) return cell_f;
66 minus (SCM x) ///((name . "-") (arity . n))
69 assert (TYPE (a) == TNUMBER);
76 assert (TYPE (car (x)) == TNUMBER);
80 return MAKE_NUMBER (n);
84 plus (SCM x) ///((name . "+") (arity . n))
89 assert (TYPE (car (x)) == TNUMBER);
93 return MAKE_NUMBER (n);
97 divide (SCM x) ///((name . "/") (arity . n))
101 assert (TYPE (car (x)) == TNUMBER);
105 while (x != cell_nil)
107 assert (TYPE (car (x)) == TNUMBER);
108 n /= VALUE (car (x));
111 return MAKE_NUMBER (n);
115 modulo (SCM a, SCM b)
117 assert (TYPE (a) == TNUMBER);
118 assert (TYPE (b) == TNUMBER);
120 while (x < 0) x += VALUE (b);
121 return MAKE_NUMBER (x % VALUE (b));
125 multiply (SCM x) ///((name . "*") (arity . n))
128 while (x != cell_nil)
130 assert (TYPE (car (x)) == TNUMBER);
131 n *= VALUE (car (x));
134 return MAKE_NUMBER (n);
138 logior (SCM x) ///((arity . n))
141 while (x != cell_nil)
143 assert (TYPE (car (x)) == TNUMBER);
144 n |= VALUE (car (x));
147 return MAKE_NUMBER (n);
151 ash (SCM n, SCM count)
153 assert (TYPE (n) == TNUMBER);
154 assert (TYPE (count) == TNUMBER);
156 int ccount = VALUE (count);
157 return MAKE_NUMBER ((ccount < 0) ? cn >> -ccount : cn << ccount);