JavaCalc is a recursive descent parser which evaluates math expressions, including a bunch of math functions and with variables support.
JavaCalc uses java.math.BigDecimal
as main type, in order not to lose precision during calculation.
BigDecimal result = Calc.eval("(2 + 2) * 3 /2");
BigDecimal result = Calc.eval("sqrt(9)*sin(3/2)");
Map<String, Number> vars = new HashMap<>();
vars.put("x", 9);
vars.put("y", 12.5);
BigDecimal result = Calc.eval("x + y*2", vars);
sqrt(x)
: square root ofx
sin(x)
: sine ofx
radiantscos(x)
: cosine ofx
radiantstan(x)
: tangent ofx
radiantsasin(x)
: arcsine ofx
acos(x)
: arccosine ofx
atan(x)
: arctangent ofx
sgn(x)
: signum ofx
(positive: 1, negative: -1, otherwise 0)abs(x)
: absolute value ofx