Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: exptree/operators/division.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   * @(#)division.java   0.1   08/19/2000
21   */
22  package exptree.operators;
23  
24  import java.io.*;
25  import exptree.*;
26  
27  /**
28   * Divides 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 division.
32   *
33   * The method used to bind the results to [-1.0,1.0] may not be optimal.
34   *
35   * @version 1.1 08/19/2000
36   * @author Andy Molloy
37   */
38  public class division implements operatorInterface, Serializable
39  {
40     /** Perform the operation. */
41     public double evaluate(expressionTree params[])
42     {
43        double a = params[0].evaluate();
44        double b = params[1].evaluate();
45        double result;
46  
47        try
48        {
49          result = a / b;
50        }
51        catch (ArithmeticException ae)
52        {
53           if (Math.abs(a) != a)   // it's either infinity or negative infinity.  We can't deal with that, tho, so set it to the maxmimum...
54           {
55              result = -Double.MAX_VALUE;
56           } else {
57              result = Double.MAX_VALUE;
58           }
59        }
60  
61        return( result );
62     }
63  
64     /** Returns the operator's name. */
65     public String getName()
66     {
67        return "div";
68     }
69  
70     /** Performs any initialization the operator requires. */
71     public void init() {}
72  
73     /** Returns the number of parameters expected by the operator. */
74     public int getNumberOfParameters() { return 2; }
75  }