All Implemented Interfaces:
PostfixMathCommandI, Serializable

public class FieldSqrt extends UnaryFunction
Calculate the square root of a number using any field. Uses the Babylonian method with the iterative formula x_{n+1} = (x_n + S / x_n) / 2 where S is the input number scaled to lie between 1/16 and 16. Algorithm will stop until convergence or the maximum number of iterations is reached.
See Also:
  • Constructor Details

    • FieldSqrt

      public FieldSqrt(FieldI f, int num_itts)
      Constructor
      Parameters:
      f - the field for all computations
      num_itts - maximum number of iterations
  • Method Details

    • eval

      public Object eval(Object arg) throws EvaluationException
      Description copied from class: UnaryFunction
      Evaluate the function
      Specified by:
      eval in class UnaryFunction
      Parameters:
      arg - the single argument passed in
      Returns:
      the result of the function
      Throws:
      EvaluationException - on error
    • getNum_itts

      public int getNum_itts()
    • setNum_itts

      public void setNum_itts(int num_itts)
    • toString

      public String toString()
      Description copied from class: PostfixMathCommand
      Return a string representation of the function. If the name is not null, return the name, otherwise return the class name.
      Overrides:
      toString in class PostfixMathCommand