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
public class Log2Function extends Object implements JepExpressionFunction
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:
Jep
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
Field Summary
Fields Modifier and Type Field Description private static double
LOG2
The natural logarithm of 2.private static Log2Function
theInstance
The one and only instance of this function. -
Constructor Summary
Constructors Modifier Constructor Description private
Log2Function()
Create a new instance of this function. -
Method Summary
Modifier and Type Method Description boolean
checkNumberOfParameters(int n)
String
getFunctionName()
Get the name of this function.static Log2Function
getInstance()
Get the singleton instance of this function.int
getNumberOfParameters()
double
log2(Number argument)
Calculate the 2-based logarithm of the argument.void
run(Stack stack)
void
setCurNumberOfParameters(int n)
Expression
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:
JEP.addFunction(String, PostfixMathCommandI)
-
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.
-