KickJava   Java API By Example, From Geeks To Geeks.

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


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

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