KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.nfunk.jep.function;
10
11 import java.lang.Math JavaDoc;
12 import java.util.*;
13 import org.nfunk.jep.*;
14 import org.nfunk.jep.type.*;
15
16 /**
17  * The acos function.
18  * @author Nathan Funk
19  * TODO How to handle acos(x) for real x with x>1 or x<-1
20  */

21 public class ArcCosine extends PostfixMathCommand
22 {
23     public ArcCosine()
24     {
25         numberOfParameters = 1;
26     
27     }
28     
29     public void run(Stack inStack)
30         throws ParseException
31     {
32         checkStack(inStack);// check the stack
33
Object JavaDoc param = inStack.pop();
34         inStack.push(acos(param));//push the result on the inStack
35
return;
36     }
37
38     public Object JavaDoc acos(Object JavaDoc param)
39         throws ParseException
40     {
41         if (param instanceof Complex)
42         {
43             return ((Complex)param).acos();
44         }
45         else if (param instanceof Number JavaDoc)
46         {
47             return new Double JavaDoc(Math.acos(((Number JavaDoc)param).doubleValue()));
48         }
49
50         throw new ParseException("Invalid parameter type");
51     }
52     
53 }
54
Popular Tags