All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jason.functions.Abs Maven / Gradle / Ivy

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