KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nfunk > jep > function > ArcTangent2


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9
10 package org.nfunk.jep.function;
11
12 import java.lang.Math JavaDoc;
13 import java.util.*;
14 import org.nfunk.jep.*;
15
16 /**
17  * atan2(y, x) Returns the angle whose tangent is y/x.
18  * @author nathan
19  */

20 public class ArcTangent2 extends PostfixMathCommand
21 {
22     public ArcTangent2()
23     {
24         numberOfParameters = 2;
25     }
26     
27     public void run(Stack inStack)
28         throws ParseException
29     {
30         checkStack(inStack);// check the stack
31
Object JavaDoc param2 = inStack.pop();
32         Object JavaDoc param1 = inStack.pop();
33         
34         if ((param1 instanceof Number JavaDoc) && (param2 instanceof Number JavaDoc))
35         {
36             double y = ((Number JavaDoc)param1).doubleValue();
37             double x = ((Number JavaDoc)param2).doubleValue();
38             inStack.push(new Double JavaDoc(Math.atan2(y, x)));//push the result on the inStack
39
}
40         else
41             throw new ParseException("Invalid parameter type");
42         return;
43     }
44 }
45
Popular Tags