Exemplo n.º 1
0
 /**
  * Call this function if you want to parse expressions which involve complex numbers. This method
  * specifies "i" as the imaginary unit (0,1). Two functions re() and im() are also added for
  * extracting the real or imaginary components of a complex number respectively.
  *
  * <p>
  *
  * @since 2.3.0 alpha The functions cmod and arg are added to get the modulus and argument.
  * @since 2.3.0 beta 1 The functions complex and polar to convert x,y and r,theta to Complex.
  * @since Feb 05 added complex conjugate conj.
  */
 public void addComplex() {
   // add constants to Symbol Table
   symTab.addConstant("i", new Complex(0, 1));
   funTab.put("re", new Real());
   funTab.put("im", new Imaginary());
   funTab.put("arg", new Arg());
   funTab.put("cmod", new Abs());
   funTab.put("complex", new ComplexPFMC());
   funTab.put("polar", new Polar());
   funTab.put("conj", new Conjugate());
 }
Exemplo n.º 2
0
 /**
  * Removes a function from the parser.
  *
  * @return If the function was added earlier, the function class instance is returned. If the
  *     function was not present, <code>null</code> is returned.
  */
 public Object removeFunction(String name) {
   return funTab.remove(name);
 }
Exemplo n.º 3
0
 /**
  * Adds a new function to the parser. This must be done before parsing an expression so the parser
  * is aware that the new function may be contained in the expression.
  *
  * @param functionName The name of the function
  * @param function The function object that is used for evaluating the function
  */
 public void addFunction(String functionName, PostfixMathCommandI function) {
   funTab.put(functionName, function);
 }
Exemplo n.º 4
0
  /**
   * Adds the standard functions to the parser. If this function is not called before parsing an
   * expression, functions such as sin() or cos() would produce an "Unrecognized function..." error.
   * In most cases, this method should be called immediately after the JEP object is created.
   *
   * @since 2.3.0 alpha added if and exp functions
   * @since 2.3.0 beta 1 added str function
   */
  public void addStandardFunctions() {
    // add functions to Function Table
    funTab.put("sin", new Sine());
    funTab.put("cos", new Cosine());
    funTab.put("tan", new Tangent());
    funTab.put("asin", new ArcSine());
    funTab.put("acos", new ArcCosine());
    funTab.put("atan", new ArcTangent());
    funTab.put("atan2", new ArcTangent2());

    funTab.put("sinh", new SineH());
    funTab.put("cosh", new CosineH());
    funTab.put("tanh", new TanH());
    funTab.put("asinh", new ArcSineH());
    funTab.put("acosh", new ArcCosineH());
    funTab.put("atanh", new ArcTanH());

    funTab.put("log", new Logarithm());
    funTab.put("ln", new NaturalLogarithm());
    funTab.put("exp", new Exp());
    funTab.put("pow", new Power());

    funTab.put("sqrt", new SquareRoot());
    funTab.put("abs", new Abs());
    funTab.put("mod", new Modulus());
    funTab.put("sum", new Sum());

    funTab.put("rand", new org.nfunk.jep.function.Random());

    // rjm additions
    funTab.put("if", new If());
    funTab.put("str", new Str());

    // rjm 13/2/05
    funTab.put("binom", new Binomial());

    // rjm 26/1/07
    funTab.put("round", new Round());
    funTab.put("floor", new Floor());
    funTab.put("ceil", new Ceil());
  }