KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.Math JavaDoc;
13 import java.util.*;
14 import org.nfunk.jep.*;
15 import org.nfunk.jep.type.*;
16
17 public class Sine extends PostfixMathCommand
18 {
19     public Sine()
20     {
21         numberOfParameters = 1;
22     }
23     
24     public void run(Stack inStack)
25         throws ParseException
26     {
27         checkStack(inStack);// check the stack
28
Object JavaDoc param = inStack.pop();
29         inStack.push(sin(param));//push the result on the inStack
30
return;
31     }
32
33     public Object JavaDoc sin(Object JavaDoc param)
34         throws ParseException
35     {
36         if (param instanceof Complex) {
37             return ((Complex)param).sin();
38         }
39         else if (param instanceof Number JavaDoc) {
40             return new Double JavaDoc(Math.sin(((Number JavaDoc)param).doubleValue()));
41         }
42         
43         throw new ParseException("Invalid parameter type");
44     }
45 }
46
Popular Tags