KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class Imaginary extends PostfixMathCommand
16 {
17     public Imaginary() {
18         numberOfParameters = 1;
19     }
20     
21     public void run(Stack inStack) throws ParseException {
22         
23         checkStack(inStack);// check the stack
24
Object JavaDoc param = inStack.pop();
25         inStack.push(im(param));//push the result on the inStack
26
return;
27     }
28     
29     public Number JavaDoc im(Object JavaDoc param) throws ParseException {
30         
31         if (param instanceof Complex)
32             return new Double JavaDoc(((Complex)param).im());
33         else if (param instanceof Number JavaDoc)
34             return new Double JavaDoc(0);
35         
36
37         throw new ParseException("Invalid parameter type");
38     }
39
40 }
41
Popular Tags