KickJava   Java API By Example, From Geeks To Geeks.

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


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
10 package org.nfunk.jep.function;
11
12 import java.util.*;
13 import org.nfunk.jep.*;
14 import org.nfunk.jep.type.*;
15 /**
16  * Converts a pair of real numbers to a complex number Complex(x,y)=x+i y.
17  *
18  * @author Rich Morris
19  * Created on 24-Mar-2004
20  */

21 public class Polar extends PostfixMathCommand
22 {
23     public Polar()
24     {
25         numberOfParameters = 2;
26     }
27     
28     public void run(Stack inStack)
29         throws ParseException
30     {
31         checkStack(inStack);// check the stack
32
Object JavaDoc param2 = inStack.pop();
33         Object JavaDoc param1 = inStack.pop();
34         
35         if ((param1 instanceof Number JavaDoc) && (param2 instanceof Number JavaDoc))
36         {
37             inStack.push(Complex.polarValueOf((Number JavaDoc) param1,(Number JavaDoc) param2));
38         }
39         else
40         {
41             throw new ParseException("Complex: Invalid parameter types "+param1.getClass().getName()+" "+param1.getClass().getName());
42         }
43         return;
44     }
45 }
46
Popular Tags