From fa1ac86ff282b74172999f655a45a1c65aa54074 Mon Sep 17 00:00:00 2001 From: dehnert Date: Mon, 18 Apr 2016 20:28:44 +0200 Subject: [PATCH] fixed evaluation of floor/ceil in expressions Former-commit-id: c3e64c552eb10f10b7317da9ad90beeab1877148 --- .../UnaryNumericalFunctionExpression.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/storage/expressions/UnaryNumericalFunctionExpression.cpp b/src/storage/expressions/UnaryNumericalFunctionExpression.cpp index 987b5b5e1..dea7b3dff 100644 --- a/src/storage/expressions/UnaryNumericalFunctionExpression.cpp +++ b/src/storage/expressions/UnaryNumericalFunctionExpression.cpp @@ -8,6 +8,7 @@ #include "ExpressionVisitor.h" #include "src/utility/macros.h" #include "src/exceptions/InvalidTypeException.h" +#include "src/exceptions/InvalidOperationException.h" namespace storm { namespace expressions { @@ -32,13 +33,19 @@ namespace storm { int_fast64_t UnaryNumericalFunctionExpression::evaluateAsInt(Valuation const* valuation) const { STORM_LOG_THROW(this->hasIntegerType(), storm::exceptions::InvalidTypeException, "Unable to evaluate expression as integer."); - int_fast64_t result = this->getOperand()->evaluateAsInt(valuation); - switch (this->getOperatorType()) { - case OperatorType::Minus: result = -result; break; - case OperatorType::Floor: result = std::floor(result); break; - case OperatorType::Ceil: result = std::ceil(result); break; + if (this->getOperatorType() == OperatorType::Minus) { + STORM_LOG_THROW(this->getOperand()->hasIntegerType(), storm::exceptions::InvalidTypeException, "Unable to evaluate expression as integer."); + int_fast64_t result = this->getOperand()->evaluateAsInt(); + return -result; + } else { + double result = this->getOperand()->evaluateAsDouble(); + switch (this->getOperatorType()) { + case OperatorType::Floor: return static_cast(std::floor(result)); break; + case OperatorType::Ceil: return static_cast(std::ceil(result)); break; + default: + STORM_LOG_ASSERT(false, "All other operator types should have been handled before."); + } } - return result; } double UnaryNumericalFunctionExpression::evaluateAsDouble(Valuation const* valuation) const { @@ -58,7 +65,6 @@ namespace storm { if (operandSimplified->isLiteral()) { boost::variant operandEvaluation; - if (operandSimplified->hasIntegerType()) { operandEvaluation = operandSimplified->evaluateAsInt(); } else {