Source code: exptree/operators/xor.java
1 /* Evolvo - Image Generator
2 * Copyright (C) 2000 Andrew Molloy
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /*
20 * @(#)xor.java 0.1 08/19/2000
21 */
22 package exptree.operators;
23
24 import java.io.*;
25 import exptree.*;
26
27 /**
28 * Returns the exclusive-or function for two expressionTrees
29 *
30 * This particular application expects all inputs and outputs on the expressionTree
31 * to be bound to [-1.0,1.0], so this function is not actually natural xor.
32 *
33 * @version 1.1 08/19/2000
34 * @author Andy Molloy
35 */
36 public class xor implements operatorInterface, Serializable
37 {
38 /** Perform the operation. */
39 public double evaluate(expressionTree params[])
40 {
41 long a, b, c;
42 a = Double.doubleToLongBits(params[0].evaluate());
43 b = Double.doubleToLongBits(params[1].evaluate());
44
45 c = a ^ b;
46
47 return Double.longBitsToDouble(c);
48 }
49
50 /** Returns the operator's name. */
51 public String getName()
52 {
53 return "xor";
54 }
55
56 /** Performs any initialization the operator requires. */
57 public void init() {}
58
59 /** Returns the number of parameters expected by the operator. */
60 public int getNumberOfParameters() { return 2; }
61 }