2 ent-binary-rel.c -- Global Binary Relations
3 Copyright (C) 2006-2012 Sebastian Freundt
5 Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 * This file is part of SXEmacs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the author nor the names of any contributors
21 * may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 /* Synched up with: Not in FSF. */
41 #include "ent-optable.h"
43 #include "ent-binary-op.h"
44 #include "ent-binary-rel.h"
46 extern Lisp_Object Qrelation_error;
48 ase_binary_relation_f ase_binary_reltable
49 [N_ASE_BINARY_OPS][ASE_OPTABLE_SIZE][ASE_OPTABLE_SIZE];
53 ase_binary_relation_undefined(Lisp_Object l, Lisp_Object r)
55 Fsignal(Qrelation_error, list2(l, r));
60 _ase_binary_reltable_init(ase_binary_relation_t rel)
63 for (i = 0; i < ASE_OPTABLE_SIZE; i++) {
64 for (j = 0; j < ASE_OPTABLE_SIZE; j++) {
65 ent_binrel_unregister(rel, i, j);
71 ase_binary_reltable_init(void)
73 ase_binary_relation_t rel;
74 for (rel = ASE_BINARY_FIRST_REL; rel < N_ASE_BINARY_RELS; rel++) {
75 _ase_binary_reltable_init(rel);
80 DEFUN("<", Fent_binrel_lessp, 1, MANY, 0, /*
81 Return t if the ARGUMENTS are strictly monotonically increasing.
82 Arguments: &rest arguments
84 If there is more than one argument, the second argument, must be
85 numerically greater than the first, and the third, must be numerically
86 greater than the second, and so on. At least one argument is required.
88 The arguments may be numbers, characters or markers.
90 (int nargs, Lisp_Object *args))
95 if (ent_binrel_transitive_many(ASE_BINARY_REL_LESSP, nargs, args))
101 DEFUN(">", Fent_binrel_greaterp, 1, MANY, 0, /*
102 Return t if the ARGUMENTS are strictly monotonically decreasing.
103 Arguments: &rest arguments
105 If there is more than one argument, the second argument, must be
106 numerically smaller than the first, and the third, must be numerically
107 smaller than the second, and so on. At least one argument is required.
109 The arguments may be numbers, characters or markers.
111 (int nargs, Lisp_Object *args))
116 if (ent_binrel_transitive_many(ASE_BINARY_REL_GREATERP, nargs, args))
122 DEFUN("<=", Fent_binrel_lessequalp, 1, MANY, 0, /*
123 Return t if the ARGUMENTS are monotonically decreasing.
124 Arguments: &rest arguments
126 If there is more than one argument, the second argument, must be
127 numerically greater than or equal to the first, and the third, must
128 be numerically greater than or equal to the second, and so on. At
129 least one argument is required.
131 The arguments may be numbers, characters or markers.
133 (int nargs, Lisp_Object * args))
138 if (ent_binrel2_transitive_many(
139 ASE_BINARY_REL_LESSP, ASE_BINARY_REL_EQUALP,
146 DEFUN(">=", Fent_binrel_greaterequalp, 1, MANY, 0, /*
147 Return t if the ARGUMENTS are monotonically increasing.
148 Arguments: &rest arguments
150 If there is more than one argument, the second argument, must be
151 numerically smaller than or equal to the first, and the third, must
152 be numerically smaller than or equal to the second, and so on. At
153 least one argument is required.
155 The arguments may be numbers, characters or markers.
157 (int nargs, Lisp_Object *args))
162 if (ent_binrel2_transitive_many(
163 ASE_BINARY_REL_GREATERP, ASE_BINARY_REL_EQUALP,
170 DEFUN("=", Fent_binrel_equalp, 1, MANY, 0, /*
171 Return t if all the arguments are numerically equal.
172 Arguments: &rest arguments
174 The arguments may be numbers, characters or markers.
176 (int nargs, Lisp_Object *args))
181 if (ent_binrel_transitive_many(ASE_BINARY_REL_EQUALP, nargs, args))
187 DEFUN("/=", Fent_binrel_neqp, 1, MANY, 0, /*
188 Return t if no two arguments are numerically equal.
189 Arguments: &rest arguments
191 The arguments may be numbers, characters or markers.
193 (int nargs, Lisp_Object *args))
198 if (ent_binrel_intransitive_many(ASE_BINARY_REL_NEQP, nargs, args))
205 DEFUN("min", Fmin, 1, MANY, 0, /*
206 Return smallest of all the arguments.
207 All arguments must be numbers, characters or markers.
208 The value is always a number; markers and characters are converted
211 (int nargs, Lisp_Object *args))
213 REGISTER int i, minindex;
214 Lisp_Object compmin, compi;
215 ase_object_type_t nti, ntmin;
218 compmin = args[minindex];
219 ntmin = ase_optable_index(compmin);
221 for (i = 1; i < nargs; i++) {
223 nti = ase_optable_index(compi);
225 if (_ent_binrel(ASE_BINARY_REL_LESSP,
226 nti, compi, ntmin, compmin)) {
232 return args[minindex];
235 DEFUN("max", Fmax, 1, MANY, 0, /*
236 Return largest of all the arguments.
237 All arguments must be numbers, characters or markers.
238 The value is always a number; markers and characters are converted
241 (int nargs, Lisp_Object *args))
243 REGISTER int i, maxindex;
244 Lisp_Object compmax, compi;
245 ase_object_type_t nti, ntmax;
248 compmax = args[maxindex];
249 ntmax = ase_optable_index(compmax);
251 for (i = 1; i < nargs; i++) {
253 nti = ase_optable_index(compi);
255 if (_ent_binrel(ASE_BINARY_REL_GREATERP,
256 nti, compi, ntmax, compmax)) {
262 return args[maxindex];
266 /* convenience functions */
270 syms_of_ent_binary_rel(void)
272 DEFSUBR(Fent_binrel_lessp);
273 DEFSUBR(Fent_binrel_greaterp);
274 DEFSUBR(Fent_binrel_lessequalp);
275 DEFSUBR(Fent_binrel_greaterequalp);
276 DEFSUBR(Fent_binrel_equalp);
277 DEFSUBR(Fent_binrel_neqp);
283 vars_of_ent_binary_rel(void)
287 /* ent-binary-rel.c ends here */