KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > logeqv


1 /*
2  * logeqv.java
3  *
4  * Copyright (C) 2003 Peter Graves
5  * $Id: logeqv.java,v 1.5 2003/12/13 00:58:51 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but 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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.lisp;
23
24 import java.math.BigInteger JavaDoc;
25
26 // ### logeqv
27
// logeqv &rest integers => result-integer
28
// equivalence (exclusive nor)
29
public final class logeqv extends Primitive
30 {
31     private logeqv()
32     {
33         super("logeqv","&rest integers");
34     }
35
36     public LispObject execute()
37     {
38         return Fixnum.MINUS_ONE;
39     }
40
41     public LispObject execute(LispObject arg) throws ConditionThrowable
42     {
43         if (arg instanceof Fixnum)
44             return arg;
45         if (arg instanceof Bignum)
46             return arg;
47         return signal(new TypeError(arg, "integer"));
48     }
49
50     public LispObject execute(LispObject[] args) throws ConditionThrowable
51     {
52         BigInteger JavaDoc result = null;
53         for (int i = 0; i < args.length; i++) {
54             LispObject arg = args[i];
55             BigInteger JavaDoc n;
56             if (arg instanceof Fixnum)
57                 n = ((Fixnum)arg).getBigInteger();
58             else if (arg instanceof Bignum)
59                 n = ((Bignum)arg).getValue();
60             else
61                 return signal(new TypeError(arg, "integer"));
62             if (result == null)
63                 result = n;
64             else
65                 result = result.xor(n).not();
66         }
67         return number(result);
68     }
69
70     private static final logeqv LOGEQV = new logeqv();
71 }
72
Popular Tags