lphy.base.function.Pow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lphy-base Show documentation
Show all versions of lphy-base Show documentation
The standard library of LPhy, which contains the required generative distributions and basic functions.
The newest version!
package lphy.base.function;
import lphy.base.ParameterNames;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;
import lphy.core.model.datatype.DoubleValue;
public class Pow extends DeterministicFunction {
final String bparamName = ParameterNames.NoParamName0;
final String xparamName = ParameterNames.NoParamName1;
public Pow(@ParameterInfo(name = bparamName, description = "the base.") Value b,
@ParameterInfo(name = xparamName, description = "the exponent.") Value x) {
// this adds value to output, so no arg name works when click sample button
setInput(bparamName, b);
setInput(xparamName, x);
}
// This cannot be built-in func, because ExpressionNode1Arg is only parsing 1-arg Function,
// and ExpressionNode2Args implemented is for BinaryOperator (not BiFunction).
@GeneratorInfo(name = "pow", description = "The power function: b^x")
public Value apply() {
Value b = getParams().get(bparamName);
Value x = getParams().get(xparamName);
return new DoubleValue(Math.pow(b.value(), x.value()), this);
}
}