Q: How can I add custom functions with a variable number of parameters?
A: Create a custom function class and set the number of parameters to -1. The parser will then accept any number of parameters.
Q: I don't need all the functions supplied by JEP. Is there a way to not load some of them, or completely remove some from the package?
A: Stripping down JEP into a lean mean arithmetic machine!
Option 1:
In some cases you will not require all the built in functions supported by JEP. The easiest way to accomplish this is simply not calling the addStandardFunctions() method before parsing. Then, you can call addFunction() for any specific functions you may require.Option 2:
If you think it is necessary to minimize the size of JEP to a minimum, you can remove all function classes other than the operators (if you don't need them). This will leave you with a parser that can still do basic arithmetic, but not the fancy functions like sin() and cos(). It saves you about 17KB of classes (15% of JEP in total).Instructions:
- The function classes are all located in the org.nfunk.jep.function package. Operators (+, -, *, /, ) are also implemented as functions. These should NOT be removed if you still want JEP to work properly. The following function classes are used to implement operators:
Add Modulus Subtract Comparative Multiply UMinus Divide Not Logical Power - Open the source code for JEP and look for the addStandardFunctions() method. It contains a list of almost all non-operator functions. For every function class you remove from the function directory, you must also remove the associated line from this method.
- Recompile JEP, and you should have a lean mean arithmetic machine!