Re: [jep-users] IllegalParameterException on Double - ?Need to implement BigDecimal?

9 views
Skip to first unread message

Richard Morris

unread,
Apr 15, 2016, 7:45:35 AM4/15/16
to Jep Java Users

On Thu, Apr 14, 2016 at 2:53 PM, Larry Villeme <lvil...@gmail.com> wrote:
We are getting the following exception below on some of the operations that have Double with a precision to the 11th decimal place or greater, e.g. Example 1. However,  in Example 2, that level of precision is only 3 decimal places and the value is well within the range of a Double. We're somewhat confused as to Example 1's IllegalArguementException (possibly the level of precision), but certainly Example #2.

Any help would be greatly appreciated.

Note: Please disregard the division by a String at the end of the equation, I overrode the Division.div(Object param1, Object param2) method to check params and throw a custom error when it's encountered.

Example 1:
==> JEP Exception: Expression {(406041.223+52380.676+18306.479+33280.723+33906.178+35507.0000000001+0.0)/"No"} caused
Exception.toString() {com.singularsys.jep.functions.IllegalParameterException: /: lllegal parameter 579422.2790000001(Double) parameter no 1}
com.singularsys.jep.functions.IllegalParameterException: /: lllegal parameter 579422.2790000001(Double) parameter no 1

Example 2:
Exception.toString() {com.singularsys.jep.functions.IllegalParameterException: /: lllegal parameter 603731.485(Double) parameter no 1}

Thanks,
Larry

Larry,

I think the problems might be with the exception generation. There is a bug here. A better code would be

    public Object div(Object param1, Object param2)
    throws EvaluationException
    {
        if (param1 instanceof Number)
        {
            if (param2 instanceof Number)
                return div((Number)param1, (Number)param2);
            if (param2 instanceof Complex)
                return div((Number)param1, (Complex)param2);
        }
        else if (param1 instanceof Complex)
        {
            if (param2 instanceof Complex)
                return div((Complex)param1, (Complex)param2);
            else if (param2 instanceof Number)
                return div((Complex)param1, (Number)param2);
        }
        else if (param1 instanceof Vector<?>)
        {
            return div((Vector<?>)param1, param2);
        }
        else
            throw new IllegalParameterException(this,0,param1);
        throw new IllegalParameterException(this,param1,param2);

    }

The first exception would reports the position and first parameter, the second exception reports
the pair of values which caused the exception. 

I'm not sure if this answers all you questions?

BTW, I can't seem to see the discussion on the group, https://groups.google.com/forum/#!forum/jep-users 



 
Reply all
Reply to author
Forward
0 new messages