com.codetaco.algebrain.function.FuncRoot Maven / Gradle / Ivy
package com.codetaco.algebrain.function;
import java.text.ParseException;
import com.codetaco.algebrain.Function;
import com.codetaco.algebrain.ValueStack;
import com.codetaco.algebrain.token.TokVariable;
/**
*
* FuncRoot class.
*
*
* @author Chris DeGreef [email protected]
* @since 1.3.9
*/
public class FuncRoot extends Function
{
/**
*
* Constructor for FuncRoot.
*
*/
public FuncRoot()
{
super();
}
/**
*
* Constructor for FuncRoot.
*
*
* @param var a {@link com.codetaco.algebrain.token.TokVariable} object.
*/
public FuncRoot(final TokVariable var)
{
super(var);
}
/** {@inheritDoc} */
@Override
public void resolve(final ValueStack values) throws Exception
{
if (values.size() < 2)
throw new Exception("missing operands for " + toString());
try
{
final double d0 = values.popDouble();
final double d1 = values.popDouble();
values.push(new Double(Math.pow(10, Math.log10(d1) / d0)));
} catch (final ParseException e)
{
e.fillInStackTrace();
throw new Exception(toString() + "; " + e.getMessage(), e);
}
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "function(root)";
}
}