Table of contents:

Using built-in evaluator

The simplest way

Javaluator comes with a built-in expression parser that is able to parse expression on real numbers.
You simply need to instanciate it (call DoubleEvaluator default constructor) and use it (call the evaluate method).

Here is a sample code:

package com.fathzer.soft.javaluator.examples;
import com.fathzer.soft.javaluator.DoubleEvaluator;
/** The most simple class to use the built-in real expression evaluator.*/
public class Simplest {
  public static void main(String[] args) {
    // Create a new evaluator
    DoubleEvaluator evaluator = new DoubleEvaluator();
    String expression = "(2^3-1)*sin(pi/4)/ln(pi^2)";
    // Evaluate an expression
    Double result = evaluator.evaluate(expression);
    // Ouput the result
    System.out.println(expression + " = " + result);

The output is (2^3-1)*sin(pi/4)/ln(pi^2) = 2.1619718020347976


Back to top