Class FromBase
- java.lang.Object
-
- com.singularsys.jep.functions.PostfixMathCommand
-
- com.singularsys.jep.functions.NaryFunction
-
- com.singularsys.jep.misc.functions.FromBase
-
- All Implemented Interfaces:
PostfixMathCommandI
,java.io.Serializable
public class FromBase extends NaryFunction
PostfixMathCommand which converts a string to a number in a given base. Instance of these classes can be specified with two different behaviours either with the base specified in the constructor or with no base specified in which case the function requires two arguments, the second of which is the base. A third form allows a prefix to be specified, this prefix must be present in the Jep expression.For example
jep.addFunction("fromDec",new FromBase(10)); jep.parse("fromDec(\"123.45\")"); jep.addFunction("fromHex",new FromBase(16,"0x")); jep.parse("fromHex(\"0xff\")"); jep.addFunction("fromBase",new FromBase()); jep.parse("fromBase(\"0377\",8)");
- Author:
- Rich Morris Created on 02-May-2005
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
eval(java.lang.Object[] args)
Evaluate the functionjava.lang.Object
fromBase(java.lang.String str, int base)
-
Methods inherited from class com.singularsys.jep.functions.NaryFunction
run
-
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
-
-
-
Method Detail
-
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
-
fromBase
public java.lang.Object fromBase(java.lang.String str, int base) throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
-