KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
12 import org.nfunk.jep.*;
13 import org.nfunk.jep.type.*;
14
15 /**
16  * Implements the arcCosH function.
17  *
18  * @author Nathan Funk
19  * @since 2.3.0 beta 2 - Now returns Double result rather than Complex for x >= 1
20  */

21 public class ArcCosineH extends PostfixMathCommand
22 {
23     public ArcCosineH()
24     {
25         numberOfParameters = 1;
26     }
27
28     public void run(Stack inStack)
29         throws ParseException
30     {
31         checkStack(inStack);// check the stack
32
Object JavaDoc param = inStack.pop();
33         inStack.push(acosh(param));//push the result on the inStack
34
return;
35     }
36
37     public Object JavaDoc acosh(Object JavaDoc param)
38         throws ParseException
39     {
40         if (param instanceof Complex)
41         {
42             return ((Complex)param).acosh();
43         }
44         else if (param instanceof Number JavaDoc)
45         {
46             double val = ((Number JavaDoc)param).doubleValue();
47             if(val >= 1.0) {
48                 double res = Math.log(val+Math.sqrt(val*val-1));
49                 return new Double JavaDoc(res);
50             }
51             else
52             {
53                 Complex temp = new Complex(((Number JavaDoc)param).doubleValue(),0.0);
54                 return temp.acosh();
55             }
56         }
57
58         throw new ParseException("Invalid parameter type");
59     }
60 }
61
Popular Tags