Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
mep4j-1.0.0-readme.txt | 2015-04-05 | 2.6 kB | |
mep4j-1.0.0.jar | 2015-04-05 | 14.5 kB | |
Totals: 2 Items | 17.1 kB | 0 |
Math Expression Parser 4 Java MEP4J is a high performance math expression strings parser for Java. The library manages the 5 operators (+, -, /, %, *) together with the following functions: - "abs" - "cos" - "sin" - "acos" - "asin" - "cosh" - "sinh" - "tan", - "tanh" - "atan" - "sqrt" - "cbrt" - "root" - "log" - "log10" - "log1p" - "exp" - "expm1" - "atan2" - "pow" The library supports variables (case insensitive), custom and pre-loaded ("e" and "pi"). Usage examples: 1. No Variables import net.sourceforge.mep4j.core.MathParser; import net.sourceforge.mep4j.core.MathParserException; ... double myRes1 = new MathParser().parse("2 * 4 - 5").execute(); 2. With Variables import net.sourceforge.mep4j.core.MathParser; import net.sourceforge.mep4j.core.MathParserException; ... double myRes1 = new MathParser().addVariable("S", 2.0).parse("s * 4 - 21").execute(); 3. Multiple executions (changing variable values) import net.sourceforge.mep4j.core.MathParser; import net.sourceforge.mep4j.core.MathParserException; ... int num_variations = 100; int init_value = 10; MathParser mathParser = new MathParser(); mathParser.addVariable("x", init_value); mathParser.parse("2 + (7 - 5) * 3.14159 * pow(x, (12-10)) + sin(-3.141)"); for(int i = init_value; i < num_variations; ++i) { Double result = mathParser.execute(); mathParser.addVariable("x", i); } Methods: Class "MathParser" - String getVersion() - Static Returns the version description - MathParser() - Constructor Instantiates the object - MathParser addVariable(String varName, Long longValue) Adds the value (name - Long value) to the parser and returns the MathParser object - MathParser addVariable(String varName, Double doubleValue) Adds the value (name - Double value) to the parser - Double getVariable(String varName) Returns the value (Double value) previously set to the parser or NULL - MathParser parse(String mathExpression) Parse the math expression to execute and returns the MathParser object. If the expression contains variables this method must be called after the "addVariable" method. - Double execute() Execute the expression previously parsed with the "parse(String)" method. If errors happened the method returns the "Double.Nan" value. - MathParserException getLastException() If the "execute()" method returns the "Double.Nan" value than this method will return the exception that describes what was wrong in the last "execute()" or "parse(String)" method call.