poidasmith / xlloop

XLLoop Excel Function (UDF) Server
104 stars 50 forks source link

IEEE 754 std for #N/A and #DIV/0 instead of XL_TYPE_ERR #19

Open sdementen opened 10 years ago

sdementen commented 10 years ago

Could the NAN and #DIV/0 be converted in standard IEEE 754 float (instead of XL_TYPE_ERR) ? For numerical packages in python/R, this would probably make sense. Moreover, this would allow to keep a single type (even in case of numerical errors) in a XL_TYPE_ARRAY (see related issue).

sebastien

mostbit commented 10 years ago

looking at Exprs.java (org.boris.expr.util)

isn't it a quick win changing simply from...

public static Expr parseValue(String expression) {
    Expr result;
    try {
        result = new ExprInteger(Integer.parseInt(expression));
    } catch (Exception e) {
        try {
            result = new ExprDouble(Double.parseDouble(expression));
        } catch (Exception ex) {
            result = new ExprString(expression);
        }
    }
    return result;
}

to

public static Expr parseValue(String expression) {
    Expr result;
    try {
        result = new ExprInteger(Integer.parseInt(expression));
    } catch (Exception e) {
        try {
           if(expression.equals("#DIV/0!"))
              result=new ExprDouble(Double.Inf);
           else if(expression.equals("#NaN"))
              result=new ExprDouble(Double.Nan);
           else
            result = new ExprDouble(Double.parseDouble(expression));
        } catch (Exception ex) {
            result = new ExprString(expression);
        }
    }
    return result;
}

would that be enough? (I see: in addition one needs to test whether "expression" is NOT of type String...)