Expression Evaluator

By Yonghe Yan, November 2006

Expression:

Result:


The Evaluator

The Expression Evaluator is a Java Applet that can evaluate an expression with double precision floating point decimal numbers. The applet uses double to represent values during the evaluation. To evaluate an expression with big integers, you may use the Big Integer Expression Evaluator, which uses java.math.BigInteger to represent values.

The Expression

Any numbers and variables whose values have been saved before can be used in the expression. The first character of any number must be a digit or a zero. The order of operations and available operators are listed as follows:

Operator Example
Assignment var = expression x=1+2*3 -> 7.0, and the value is saved in variable x.
Function see list below sin(pi/2) -> 1.0
Parenthesis, negative (expression), - (1+2)/5 -> 0.6
Exponentiation,
Modular exponentiation
^,
m^e%n
10^0.5 -> 3.1622776601683795,
65^5%119 -> 46.0
Multiplication, division, modulus *, /, % 2/3 -> 0.6666666666666666
Addition, subtraction +, - 1+2 -> 3.0

The Functions

Available functions are listed as follows:

pi the double value that is closer than any other to pi.
rand a random value, greater than or equal to 0.0 and less than 1.0.
abs(x) the absolute value of x
acos(x) the arc cosine of x, in the range of 0.0 through pi.
asin(x) the arc sine of x, in the range of -pi/2 through pi/2.
atan(x) the arc tangent of x, in the range of -pi/2 through pi/2.
cbrt(x) the cube root of x.
ceil(x) the smallest (closest to negative infinity) double value that is greater than or equal to x and is equal to a mathematical integer.
cos(x) the trigonometric cosine of x.
cosh(x) the hyperbolic cosine of x.
deg(x) Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
exp(x) Euler's number e raised to the power of x.
floor(x) the largest (closest to positive infinity) double value that is less than or equal to x and is equal to a mathematical integer.
ln(x) the natural logarithm (base e) of x.
log(x) the base 10 logarithm of x.
max(x, y) the greater of two values.
min(x, y) the smaller of two values.
mod(x, y) Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.
rad(x) Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
rint(x) the value that is closest in value to x and is equal to a mathematical integer.
sin(x) the trigonometric sine of x.
sinh(x) the hyperbolic sine of x.
sqrt(x) the correctly rounded positive square root of x.
tan(x) the trigonometric tangent of an angle.
tanh(x) the hyperbolic tangent of a double value.

Source Codes

The source codes can download here: BigIntegerExpression.zip.

You can use it for any purpose without restriction. I do not guarantee that it is correct, so use it at your own risk.

Permission is granted to copy and distribute source codes, provided that the following credit line is included: "Expression Evaluator, Yonghe Yan 2006." Permission is granted to alter and distribute source codes, provided that the following credit line is included: "Adapted from Expression Evaluator, Yonghe Yan 2006."