// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   StdFunction.java

package lt.monarch.function;

import lt.monarch.function.node.ConstantNode;
import lt.monarch.function.node.DivNode;
import lt.monarch.function.node.IdentifierNode;
import lt.monarch.function.node.NegativeNode;

// Referenced classes of package lt.monarch.function:
//			Identifier, MacroParameter, MacroFunction, Node, 
//			NodeCompiler

public class StdFunction
	implements Identifier
{

	public static final int SIN = 1;
	public static final int COS = 2;
	public static final int ABS = 3;
	public static final int LOG = 4;
	private int function;

	public boolean isConstant()
	{
		return false;
	}

	public String name()
	{
		switch(function)
		{
		case 1: // '\001'
			return "sin";

		case 2: // '\002'
			return "cos";

		case 3: // '\003'
			return "abs";

		case 4: // '\004'
			return "ln";
		}
		return null;
	}

	protected String javaMathFunctionName()
	{
		switch(function)
		{
		case 1: // '\001'
			return "sin";

		case 2: // '\002'
			return "cos";

		case 3: // '\003'
			return "abs";

		case 4: // '\004'
			return "log";
		}
		return null;
	}

	public int parameterCount()
	{
		return 1;
	}

	public double evaluate(double ad[])
	{
		switch(function)
		{
		case 1: // '\001'
			return Math.sin(ad[0]);

		case 2: // '\002'
			return Math.cos(ad[0]);

		case 3: // '\003'
			return Math.abs(ad[0]);

		case 4: // '\004'
			return Math.log(ad[0]);
		}
		return (double)0;
	}

	public Identifier derivative(int i)
	{
		MacroParameter macroparameter = new MacroParameter("x");
		MacroParameter amacroparameter[] = {
			macroparameter
		};
		switch(function)
		{
		case 1: // '\001'
			return (Identifier)new MacroFunction("sin'", amacroparameter, new IdentifierNode(new StdFunction(2), new IdentifierNode(macroparameter)));

		case 2: // '\002'
			return (Identifier)new MacroFunction("cos'", amacroparameter, new NegativeNode(new IdentifierNode(new StdFunction(1), new IdentifierNode(macroparameter))));

		case 3: // '\003'
			return (Identifier)new StdFunction(3);

		case 4: // '\004'
			return (Identifier)new MacroFunction("ln'", amacroparameter, new DivNode(new ConstantNode(1.0D), new IdentifierNode(macroparameter)));
		}
		return null;
	}

	public void compileRef(NodeCompiler nodecompiler, Node anode[])
	{
		anode[0].compile(nodecompiler);
		nodecompiler.appendStaticCall("java.lang.Math", javaMathFunctionName(), "(D)D");
	}

	public StdFunction(int i)
	{
		function = i;
	}
}
