Package net.sf.basedb.util.jep
Class Log2Function
java.lang.Object
net.sf.basedb.util.jep.Log2Function
- All Implemented Interfaces:
JepExpressionFunction
,JepFunction
,org.nfunk.jep.function.PostfixMathCommandI
A JEP function class that adds a
log2(expression)
function to a
JEP expression parser. The function will look take the 2-based logarithm of
it's argument.
This function is added automatically by the Jep.newJep(String, JepFunction[])
method to the parser.
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final double
The natural logarithm of 2.private static final Log2Function
The one and only instance of this function. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNumberOfParameters
(int n) Get the name of this function.static Log2Function
Get the singleton instance of this function.int
double
Calculate the 2-based logarithm of the argument.void
void
setCurNumberOfParameters
(int n) toExpression
(Node node) Use theExpressions.log2(Expression)
method to create an expression taking the 2-based logarithm of the argument.
-
Field Details
-
theInstance
The one and only instance of this function. -
LOG2
private static final double LOG2The natural logarithm of 2. This is used when calculating the 2-based logarithm of a value since it can be calculated as:ln(x) / ln(2)
-
-
Constructor Details
-
Log2Function
private Log2Function()Create a new instance of this function.
-
-
Method Details
-
getInstance
Get the singleton instance of this function.- Returns:
- The Log2Function object
-
getFunctionName
Description copied from interface:JepFunction
Get the name of this function. It is used when registering the function with aJEP
parser.- Specified by:
getFunctionName
in interfaceJepFunction
- Returns:
- The string "log2"
- See Also:
-
toExpression
Use theExpressions.log2(Expression)
method to create an expression taking the 2-based logarithm of the argument.- Specified by:
toExpression
in interfaceJepExpressionFunction
- Parameters:
node
- The node representing this function- Returns:
- An
Expression
object
-
getNumberOfParameters
public int getNumberOfParameters()- Specified by:
getNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Returns:
- Always 1
-
setCurNumberOfParameters
public void setCurNumberOfParameters(int n) - Specified by:
setCurNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) - Specified by:
checkNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
run
- Specified by:
run
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Throws:
ParseException
-
log2
Calculate the 2-based logarithm of the argument.- Parameters:
argument
- A number to calculate on- Returns:
- a double object
- Throws:
ParseException
- If the logarithm could not be calculated.
-