KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Argument of a complex number
17  * @author Rich Morris
18  * Created on 20-Nov-2003
19  */

20 public class Arg extends PostfixMathCommand
21 {
22     private static final Double JavaDoc ONE = new Double JavaDoc(1.0);
23     public Arg()
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(arg(param));//push the result on the inStack
34
return;
35     }
36     
37     public Number JavaDoc arg(Object JavaDoc param) throws ParseException {
38         if (param instanceof Complex) {
39                     return new Double JavaDoc(((Complex)param).arg());
40                 }
41         else if (param instanceof Number JavaDoc) {
42             return (ONE);
43         }
44         throw new ParseException("Invalid parameter type");
45     }
46
47 }
48
Popular Tags