
jason.functions.Abs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jason Show documentation
Show all versions of jason Show documentation
Jason is a programming language to develop BDI/cognitive agents
The newest version!
package jason.functions;
import jason.JasonException;
import jason.asSemantics.DefaultArithFunction;
import jason.asSemantics.TransitionSystem;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Term;
/**
Function: math.abs(N)
: encapsulates java Math.abs(N).
Examples:
-
math.abs(1)
: returns 1.
-
math.abs(-1)
: returns 1.
@author Jomi
*/
public class Abs extends DefaultArithFunction {
public String getName() {
return "math.abs";
}
@Override
public double evaluate(TransitionSystem ts, Term[] args) throws Exception {
if (args[0].isNumeric()) {
double n = ((NumberTerm)args[0]).solve();
return Math.abs(n);
} else {
throw new JasonException("The argument '"+args[0]+"' is not numeric!");
}
}
@Override
public boolean checkArity(int a) {
return a == 1;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy