com.obdobion.algebrain.function.FuncDegreesToRads Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algebrain Show documentation
Show all versions of algebrain Show documentation
Equation processing for Java
The newest version!
package com.obdobion.algebrain.function;
import java.text.ParseException;
import com.obdobion.algebrain.Function;
import com.obdobion.algebrain.ValueStack;
import com.obdobion.algebrain.token.TokVariable;
/**
*
* FuncDegreesToRads class.
*
*
* @author Chris DeGreef [email protected]
* @since 1.3.9
*/
public class FuncDegreesToRads extends Function
{
/**
*
* Constructor for FuncDegreesToRads.
*
*/
public FuncDegreesToRads()
{
super();
}
/**
*
* Constructor for FuncDegreesToRads.
*
*
* @param var a {@link com.obdobion.algebrain.token.TokVariable} object.
*/
public FuncDegreesToRads(final TokVariable var)
{
super(var);
}
/** {@inheritDoc} */
@Override
public void resolve(final ValueStack values) throws Exception
{
if (values.size() < 1)
throw new Exception("missing operands for " + toString());
try
{
final double degrees = values.popDouble();
final double rads = degrees * (Math.PI / 180);
values.push(new Double(rads));
} catch (final ParseException e)
{
e.fillInStackTrace();
throw new Exception(toString() + "; " + e.getMessage(), e);
}
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "function(rad)";
}
}