Data Types

Jep.Net supports a number of different data types in the standard mode. These include numbers, strings, arrays, and complex numbers. By default numbers are represented by the double data type, which is wrapped in the JepDouble class. When creating Variables and expression you can use double or JepDouble, but you will need to use JepDouble exclusively when creating custom functions. It is however possible to change the internal representation as described in the section on Custom types.

Strings

Strings can be entered in an expression by using double quotes. They can be concatenated with the + operator and compared with the == and != relational operators. A sample expression involving the string type is "foo" + "bar" == "foobar", which would be evaluated by Jep.Net as true.

To add a string as a variable, use the AddVariable(String name, Object value) method. If the result of an expression is a string, it can be obtained by calling the Evaluate() function.

top

Arrays

Arrays are ordered sets of Double elements. An array is a list of values, separated by commas, and enclosed by square brackets. Some example expressions involving arrays are listed below

[3, 4, 5]*2  // evaluates as [6, 8, 10]

a = [2, 3, 10]

a[1] // evaluates as 2

a[3] //evaluates as 10

To add an array as variable, use the AddVariable(String name, Object value) method where value is an instance of ArrayList. If the result of an expression is an array, it can be obtained by calling the Evaluate() method (it will be returned as ArrayList).

You can access elements of an array using square brackets. For example, to access the second element of an array v, use v[2] to access its value.

top

Complex numbers

Jep.Net supports complex numbers in most operators and functions. The complex imaginary unit i is part of the standard variable table and is added to the parser when using the StandardComponents. A set of complex functions are also included. These include re(c), im(c), cmod(c), arg(c), conj(c), complex(x, y) and polar(r, theta). See the functions page for more information on these functions. You will need to add the SingularSys.Jep.Types namespace to be able to manipulate complex values from expressions.

By using the imaginary unit constant i, you can work with complex numbers in your expressions. Some sample complex expressions are listed below:

(1+2*i)^3
e^(-i)
re((1+2*i)^2 - (3+3*i)^2)
To obtain a complex value from an expression, you must use the Evaluate() method. It will evaluate the expression and return the result as a Complex object. You will need to manually cast the Object returned to the Complex type.

Adding a complex variable or constant to the parser before evaluating an expression can be done with AddVariable(String name, double re, double im). It takes three parameters: the name of the variable as string, the real component, and the imaginary component.

top

Custom types

In most cases, you will only need to work with the few built in types that Jep.Net supplies (Double, Complex, Array, String). But suppose you want to evaluate expressions that involve other types. You may want to let variables have custom types, or create numbers with custom types.

You can create variables with custom types by using the AddVariable(String name, Object value) method.

You can ensure that numbers are created with a specific type by setting the number factory. Simply implement the INumberFactory interface, implement the CreateNumber(String) method, and set the NumFac property to load your number factory class into Jep.

When an expression is evaluated, values are operated on with the classes in the function package. These include the operators (such as Add and Subtract), as well as the functions (such as Sine and Cosine). Without making modifications to the source code, only the default types are handled with these classes. So, in order to be able to handle your own types, you will need to modify theses classes, or make your own function classes as described in the custom functions section. For more information see the custom functions section.

top