/** <b>#VALUE!</b> - Wrong type of operand */ public static EvaluationException invalidValue() { return new EvaluationException(ErrorEval.VALUE_INVALID); } /** <b>#REF!</b> - Illegal or deleted cell reference */
protected double evaluate(double d0, double d1) throws EvaluationException { if (d1 == 0.0) { throw new EvaluationException(ErrorEval.DIV_ZERO); } return d0/d1; } };
protected double evaluate(double d0, double d1) throws EvaluationException { if (d0 == ZERO && d1 == ZERO) { throw new EvaluationException(ErrorEval.DIV_ZERO); } return Math.atan2(d1, d0); } };
/** * Excel does not support infinities and NaNs, rather, it gives a #NUM! error in these cases * * @throws EvaluationException (#NUM!) if <tt>result</tt> is <tt>NaN</> or <tt>Infinity</tt> */ static void checkValue(double result) throws EvaluationException { if (Double.isNaN(result) || Double.isInfinite(result)) { throw new EvaluationException(ErrorEval.NUM_ERROR); } } }
/** * @throws EvaluationException (#NUM!) if <tt>result</tt> is <tt>NaN</> or <tt>Infinity</tt> */ public static void checkValue(double result) throws EvaluationException { if (Double.isNaN(result) || Double.isInfinite(result)) { throw new EvaluationException(ErrorEval.NUM_ERROR); } }
public static void checkValues(double[] results) throws EvaluationException { for (double result : results) { if (Double.isNaN(result) || Double.isInfinite(result)) { throw new EvaluationException(ErrorEval.NUM_ERROR); } } }
protected double[] collectValues(ValueEval arg) throws EvaluationException { double values[] = instance.collectValues(arg); /* handle case where MMULT is operating on an array that is not completely filled*/ if (arg instanceof AreaEval && values.length == 1) throw new EvaluationException(ErrorEval.VALUE_INVALID); return values; }
protected double evaluate(double[] values) throws EvaluationException { if (values.length < 1) { throw new EvaluationException(ErrorEval.DIV_ZERO); } return StatsLib.stdev(values); } };
private static BaseRef evaluateBaseRef(ValueEval eval) throws EvaluationException { if(eval instanceof RefEval) { return new BaseRef((RefEval)eval); } if(eval instanceof AreaEval) { return new BaseRef((AreaEval)eval); } if (eval instanceof ErrorEval) { throw new EvaluationException((ErrorEval) eval); } throw new EvaluationException(ErrorEval.VALUE_INVALID); }
private static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException { if (eval instanceof AreaEval) { return (AreaEval) eval; } if (eval instanceof RefEval) { return ((RefEval)eval).offset(0, 0, 0, 0); } throw new EvaluationException(ErrorEval.VALUE_INVALID); }
protected double evaluate(double d0, double d1) throws EvaluationException { if (d0 > Integer.MAX_VALUE || d1 > Integer.MAX_VALUE) { throw new EvaluationException(ErrorEval.NUM_ERROR); } return MathX.nChooseK((int) d0, (int) d1); } };
private static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException { if (eval instanceof AreaEval) { return (AreaEval) eval; } if (eval instanceof RefEval) { return ((RefEval)eval).offset(0, 0, 0, 0); } throw new EvaluationException(ErrorEval.VALUE_INVALID); }
protected double[] collectValues(ValueEval arg) throws EvaluationException { double[] values = instance.collectValues(arg); /* handle case where MDETERM is operating on an array that that is not completely filled*/ if (arg instanceof AreaEval && values.length == 1) throw new EvaluationException(ErrorEval.VALUE_INVALID); return values; }
protected double evaluate(double[] values) throws EvaluationException { if (values.length < 1) { throw new EvaluationException(ErrorEval.DIV_ZERO); } return MathX.average(values); } };
protected double evaluate(double[] values) throws EvaluationException { if (values.length < 1) { throw new EvaluationException(ErrorEval.DIV_ZERO); } return StatsLib.varp(values); } };
protected double evaluate(double d0, double d1) throws EvaluationException { if (d1 == ZERO) { if (d0 == ZERO) { return ZERO; } throw new EvaluationException(ErrorEval.DIV_ZERO); } return MathX.floor(d0, d1); } };
protected final double eval(ValueEval[] args, int srcCellRow, int srcCellCol) throws EvaluationException { if (args.length != 1) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } double d = singleOperandEvaluate(args[0], srcCellRow, srcCellCol); return evaluate(d); } protected abstract double evaluate(double d) throws EvaluationException;
protected double[][] evaluate(double[][] d1) throws EvaluationException { if (d1.length != d1[0].length) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } double result[][] = new double[1][1]; Array2DRowRealMatrix temp = new Array2DRowRealMatrix(d1); result[0][0] = (new LUDecomposition(temp)).getDeterminant(); return result; } };
protected double[][] evaluate(double[][] d1, double[][] d2) throws EvaluationException{ Array2DRowRealMatrix first = new Array2DRowRealMatrix(d1); Array2DRowRealMatrix second = new Array2DRowRealMatrix(d2); try { MatrixUtils.checkMultiplicationCompatible(first, second); } catch (DimensionMismatchException e) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } return first.multiply(second).getData(); } };
private static AreaEval createOffset(BaseRef baseRef, LinearOffsetRange orRow, LinearOffsetRange orCol) throws EvaluationException { LinearOffsetRange absRows = orRow.normaliseAndTranslate(baseRef.getFirstRowIndex()); LinearOffsetRange absCols = orCol.normaliseAndTranslate(baseRef.getFirstColumnIndex()); if(absRows.isOutOfBounds(0, LAST_VALID_ROW_INDEX)) { throw new EvaluationException(ErrorEval.REF_INVALID); } if(absCols.isOutOfBounds(0, LAST_VALID_COLUMN_INDEX)) { throw new EvaluationException(ErrorEval.REF_INVALID); } return baseRef.offset(orRow.getFirstIndex(), orRow.getLastIndex(), orCol.getFirstIndex(), orCol.getLastIndex()); }