Package com.singularsys.jep.functions
Class Round
- java.lang.Object
-
- com.singularsys.jep.functions.PostfixMathCommand
-
- com.singularsys.jep.functions.NaryFunction
-
- com.singularsys.jep.functions.Round
-
- All Implemented Interfaces:
PostfixMathCommandI
,java.io.Serializable
- Direct Known Subclasses:
BigDecRound
,RInt
public class Round extends NaryFunction
A PostfixMathCommandI which rounds a number.
round(a) adds 0.5 to the argument and returns the closest integer.
round(a,3) rounds the argument to 3 decimal places.Note: This class was changed in version 3.4. Prior to 3.4, this class used the Math.rint method. In 3.4 and future releases Math.round will be used instead. The effect is changing the rounding behaviour when the input is equally close to two integers, Math.round rounds 1.5 down and Math.rint round it up.
- Author:
- Richard Morris
- See Also:
RInt
, Serialized Form
-
-
Field Summary
-
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
-
Constructor Summary
Constructors Constructor Description Round()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkNumberOfParameters(int n)
Must have one or more parameterjava.lang.Object
eval(java.lang.Object[] args)
Evaluate the functionprotected double
round(double val)
The rounding method which implements the core rounding operation used in this class.java.lang.Object
round(java.lang.Object param)
java.lang.Object
round(java.lang.Object l, java.lang.Object r)
void
run(java.util.Stack<java.lang.Object> inStack)
Creates an array of object then callsNaryFunction.eval(Object[])
-
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
-
-
-
Method Detail
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n)
Must have one or more parameter- Specified by:
checkNumberOfParameters
in interfacePostfixMathCommandI
- Overrides:
checkNumberOfParameters
in classPostfixMathCommand
- Parameters:
n
- number of parameters function will be called with.- Returns:
- false if an illegal number of parameters is supplied, true otherwise.
-
run
public void run(java.util.Stack<java.lang.Object> inStack) throws EvaluationException
Description copied from class:NaryFunction
Creates an array of object then callsNaryFunction.eval(Object[])
- Specified by:
run
in interfacePostfixMathCommandI
- Overrides:
run
in classNaryFunction
- Parameters:
inStack
- arguments for function- Throws:
EvaluationException
- if function cannot be evaluated
-
round
public java.lang.Object round(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
round
public java.lang.Object round(java.lang.Object param) throws EvaluationException
- Throws:
EvaluationException
-
round
protected double round(double val)
The rounding method which implements the core rounding operation used in this class. Other subclasses (such as RInt) can override this to perform custom rounding.- Parameters:
val
- number to round- Returns:
- the rounded value
- Since:
- 3.4.0
-
eval
public java.lang.Object eval(java.lang.Object[] args) throws EvaluationException
Description copied from class:NaryFunction
Evaluate the function- Specified by:
eval
in classNaryFunction
- Parameters:
args
- arguments to the function- Returns:
- value returned by the function
- Throws:
EvaluationException
- if the calculation cannot be performed
-
-