KickJava   Java API By Example, From Geeks To Geeks.

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


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 arcSinH function.
17  *
18  * @author Nathan Funk
19  * @since 2.3.0 beta 2 - Now returns Double result rather than Complex for Double arguments.
20  */

21 public class ArcSineH extends PostfixMathCommand
22 {
23     public ArcSineH()
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(asinh(param));//push the result on the inStack
34
return;
35     }
36
37     public Object JavaDoc asinh(Object JavaDoc param)
38         throws ParseException
39     {
40         if (param instanceof Complex)
41         {
42             return ((Complex)param).asinh();
43         }
44         else if (param instanceof Number JavaDoc)
45         {
46             double val = ((Number JavaDoc)param).doubleValue();
47             double res = Math.log(val+Math.sqrt(val*val+1));
48             return new Double JavaDoc(res);
49 // Complex temp = new Complex(((Number)param).doubleValue(),0.0);
50
// return temp.asinh();
51
}
52         throw new ParseException("Invalid parameter type");
53     }
54 }
55
Popular Tags