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
,Serializable
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:
-
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
Constructor Summary
-
Method Summary
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
-
Constructor Details
-
FromBase
public FromBase() -
FromBase
public FromBase(int base) -
FromBase
-
-
Method Details
-
eval
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
- Throws:
NumberFormatException
-