Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package jason.functions;
 

Function: math.sqrt(N): encapsulates java Math.sqrt(N); returns the correctly rounded positive square root of N.

Example:

  • math.sqrt(9): returns 3.

Author(s):
Jomi
public class Sqrt extends DefaultArithFunction  {
    public String getName() {
        return "math.sqrt";
    }
    
    @Override
    public double evaluate(TransitionSystem tsTerm[] argsthrows Exception {
        if (args[0].isNumeric()) {
            double n = ((NumberTerm)args[0]).solve();
            return Math.sqrt(n);
        } else {
            throw new JasonException("The argument '"+args[0]+"' is not numeric!");
        }
    }
    @Override
    public boolean checkArity(int a) {
        return a == 1;
    }
    
New to GrepCode? Check out our FAQ X