From 4317643abf601cbe47d42a16ecd89983ccae6d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=A4rcker?= Date: Wed, 16 May 2018 10:45:32 +0200 Subject: [PATCH] Check argument instead of result in function evaluation Make the check intention revealing, i.e., we do not floor/ceil special values. --- prism/src/parser/ast/ExpressionFunc.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/prism/src/parser/ast/ExpressionFunc.java b/prism/src/parser/ast/ExpressionFunc.java index c399be0a..b6cece35 100644 --- a/prism/src/parser/ast/ExpressionFunc.java +++ b/prism/src/parser/ast/ExpressionFunc.java @@ -284,10 +284,10 @@ public class ExpressionFunc extends Expression return max; } - public Object evaluateFloor(EvaluateContext ec) throws PrismLangException + public Integer evaluateFloor(EvaluateContext ec) throws PrismLangException { try { - return new Integer(evaluateFloor(getOperand(0).evaluateDouble(ec))); + return evaluateFloor(getOperand(0).evaluateDouble(ec)); } catch (PrismLangException e) { e.setASTElement(this); throw e; @@ -296,17 +296,16 @@ public class ExpressionFunc extends Expression public static int evaluateFloor(double arg) throws PrismLangException { - double d = Math.floor(arg); // Check for NaN or +/-inf, otherwise possible errors lost in cast to int - if (Double.isNaN(d) || Double.isInfinite(d)) - throw new PrismLangException("Cannot take floor() of " + d); - return (int) d; + if (Double.isNaN(arg) || Double.isInfinite(arg)) + throw new PrismLangException("Cannot take floor() of " + arg); + return (int) Math.floor(arg); } - public Object evaluateCeil(EvaluateContext ec) throws PrismLangException + public Integer evaluateCeil(EvaluateContext ec) throws PrismLangException { try { - return new Integer(evaluateCeil(getOperand(0).evaluateDouble(ec))); + return evaluateCeil(getOperand(0).evaluateDouble(ec)); } catch (PrismLangException e) { e.setASTElement(this); throw e;