Browse Source

fixed evaluation of floor/ceil in expressions

Former-commit-id: c3e64c552e
tempestpy_adaptions
dehnert 9 years ago
parent
commit
fa1ac86ff2
  1. 18
      src/storage/expressions/UnaryNumericalFunctionExpression.cpp

18
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);
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::Minus: result = -result; break;
case OperatorType::Floor: result = std::floor(result); break;
case OperatorType::Ceil: result = std::ceil(result); break;
case OperatorType::Floor: return static_cast<int_fast64_t>(std::floor(result)); break;
case OperatorType::Ceil: return static_cast<int_fast64_t>(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<int_fast64_t, double> operandEvaluation;
if (operandSimplified->hasIntegerType()) {
operandEvaluation = operandSimplified->evaluateAsInt();
} else {

Loading…
Cancel
Save