Browse Source

added floor/ceil to jit builder (rational numbers)

tempestpy_adaptions
dehnert 8 years ago
parent
commit
d676f768dc
  1. 24
      src/storm/storage/expressions/ToCppVisitor.cpp

24
src/storm/storage/expressions/ToCppVisitor.cpp

@ -2,6 +2,11 @@
#include "storm/storage/expressions/Expressions.h" #include "storm/storage/expressions/Expressions.h"
#include "storm/adapters/CarlAdapter.h"
#include "storm/utility/macros.h"
#include "storm/exceptions/NotSupportedException.h"
namespace storm { namespace storm {
namespace expressions { namespace expressions {
@ -251,6 +256,7 @@ namespace storm {
} }
boost::any ToCppVisitor::visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) { boost::any ToCppVisitor::visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) {
ToCppTranslationOptions const& options = boost::any_cast<ToCppTranslationOptions const&>(data);
switch (expression.getOperatorType()) { switch (expression.getOperatorType()) {
case UnaryNumericalFunctionExpression::OperatorType::Minus: case UnaryNumericalFunctionExpression::OperatorType::Minus:
stream << "-("; stream << "-(";
@ -258,12 +264,24 @@ namespace storm {
stream << ")"; stream << ")";
break; break;
case UnaryNumericalFunctionExpression::OperatorType::Floor: 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); expression.getOperand()->accept(*this, data);
stream << ")"; stream << ")";
break; break;
case UnaryNumericalFunctionExpression::OperatorType::Ceil: 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); expression.getOperand()->accept(*this, data);
stream << ")"; stream << ")";
break; break;
@ -299,7 +317,7 @@ namespace storm {
ToCppTranslationOptions const& options = boost::any_cast<ToCppTranslationOptions const&>(data); ToCppTranslationOptions const& options = boost::any_cast<ToCppTranslationOptions const&>(data);
switch (options.getMode()) { switch (options.getMode()) {
case ToCppTranslationMode::KeepType: case ToCppTranslationMode::KeepType:
stream << expression.getValueAsDouble();
stream << "(static_cast<double>(" << carl::getNum(expression.getValue()) << ")/carl::getDenom(expression.getValue()))";
break; break;
case ToCppTranslationMode::CastDouble: case ToCppTranslationMode::CastDouble:
stream << "static_cast<double>(" << expression.getValueAsDouble() << ")"; stream << "static_cast<double>(" << expression.getValueAsDouble() << ")";

Loading…
Cancel
Save