Class 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
    • Constructor Detail

      • FromBase

        public FromBase()
      • FromBase

        public FromBase​(int base)
      • FromBase

        public FromBase​(int base,
                        java.lang.String prefix)
    • 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 class NaryFunction
        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