From d676f768dc0c98cd249e8b6c1328d796a2e34583 Mon Sep 17 00:00:00 2001 From: dehnert Date: Fri, 13 Jan 2017 10:24:31 +0100 Subject: [PATCH] added floor/ceil to jit builder (rational numbers) --- .../storage/expressions/ToCppVisitor.cpp | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/storm/storage/expressions/ToCppVisitor.cpp b/src/storm/storage/expressions/ToCppVisitor.cpp index 40e75b152..25b7dd5a3 100644 --- a/src/storm/storage/expressions/ToCppVisitor.cpp +++ b/src/storm/storage/expressions/ToCppVisitor.cpp @@ -2,6 +2,11 @@ #include "storm/storage/expressions/Expressions.h" +#include "storm/adapters/CarlAdapter.h" + +#include "storm/utility/macros.h" +#include "storm/exceptions/NotSupportedException.h" + namespace storm { namespace expressions { @@ -251,6 +256,7 @@ namespace storm { } boost::any ToCppVisitor::visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) { + ToCppTranslationOptions const& options = boost::any_cast(data); switch (expression.getOperatorType()) { case UnaryNumericalFunctionExpression::OperatorType::Minus: stream << "-("; @@ -258,12 +264,24 @@ namespace storm { stream << ")"; break; case UnaryNumericalFunctionExpression::OperatorType::Floor: - stream << "std::floor("; + STORM_LOG_THROW(options.getMode() != ToCppTranslationMode::CastRationalFunction, storm::exceptions::NotSupportedException, "Floor is not supported by rational functions."); + if (options.getMode() != ToCppTranslationMode::CastRationalNumber) { + stream << "std::floor"; + } else { + stream << "carl::floor"; + } + stream << "("; expression.getOperand()->accept(*this, data); stream << ")"; break; case UnaryNumericalFunctionExpression::OperatorType::Ceil: - stream << "std::ceil("; + STORM_LOG_THROW(options.getMode() != ToCppTranslationMode::CastRationalFunction, storm::exceptions::NotSupportedException, "Ceil is not supported by rational functions."); + if (options.getMode() != ToCppTranslationMode::CastRationalNumber) { + stream << "std::ceil"; + } else { + stream << "carl::ceil"; + } + stream << "("; expression.getOperand()->accept(*this, data); stream << ")"; break; @@ -299,7 +317,7 @@ namespace storm { ToCppTranslationOptions const& options = boost::any_cast(data); switch (options.getMode()) { case ToCppTranslationMode::KeepType: - stream << expression.getValueAsDouble(); + stream << "(static_cast(" << carl::getNum(expression.getValue()) << ")/carl::getDenom(expression.getValue()))"; break; case ToCppTranslationMode::CastDouble: stream << "static_cast(" << expression.getValueAsDouble() << ")";