Source code: exptree/operators/absolute.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 * @(#)absolute.java 0.1 08/19/2000
21 */
22 package exptree.operators;
23
24 import java.io.*;
25 import exptree.*;
26
27 /**
28 * Returns the absolute value of its parameter.
29 *
30 * @version 1.1 08/19/2000
31 * @author Andy Molloy
32 */
33 public class absolute implements operatorInterface, Serializable
34 {
35 /** Performs the operation. */
36 public double evaluate(expressionTree params[])
37 {
38 return( Math.abs(params[0].evaluate()) );
39 }
40
41 /** Returns the operator's name. */
42 public String getName()
43 {
44 return "abs";
45 }
46
47 /** Performs any initialization the operator requires. */
48 public void init() {}
49
50 /** Returns the number of parameters expected by the operator. */
51 public int getNumberOfParameters() { return 1; }
52 }