diff --git a/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp b/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp index 371dfab34..fb71fa43f 100644 --- a/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp +++ b/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp @@ -829,7 +829,7 @@ namespace storm { TemporaryHelper::swapSolutions(rationalX, temporaryRational, x, currentX, newX); } else { // Increase the precision. - precision /= 10; + precision /= storm::utility::convertNumber(static_cast(10)); } } diff --git a/src/storm/storage/dd/cudd/CuddAddIterator.cpp b/src/storm/storage/dd/cudd/CuddAddIterator.cpp index 19e148390..d817a79d3 100644 --- a/src/storm/storage/dd/cudd/CuddAddIterator.cpp +++ b/src/storm/storage/dd/cudd/CuddAddIterator.cpp @@ -183,7 +183,7 @@ namespace storm { template std::pair AddIterator::operator*() const { - return std::make_pair(currentValuation, static_cast(valueAsDouble)); + return std::make_pair(currentValuation, storm::utility::convertNumber(valueAsDouble)); } template class AddIterator; diff --git a/src/storm/storage/dd/cudd/InternalCuddAdd.cpp b/src/storm/storage/dd/cudd/InternalCuddAdd.cpp index 325f0ad9a..83ace48ae 100644 --- a/src/storm/storage/dd/cudd/InternalCuddAdd.cpp +++ b/src/storm/storage/dd/cudd/InternalCuddAdd.cpp @@ -325,18 +325,18 @@ namespace storm { template ValueType InternalAdd::getMin() const { cudd::ADD constantMinAdd = this->getCuddAdd().FindMin(); - return static_cast(Cudd_V(constantMinAdd.getNode())); + return storm::utility::convertNumber(Cudd_V(constantMinAdd.getNode())); } template ValueType InternalAdd::getMax() const { cudd::ADD constantMaxAdd = this->getCuddAdd().FindMax(); - return static_cast(Cudd_V(constantMaxAdd.getNode())); + return storm::utility::convertNumber(Cudd_V(constantMaxAdd.getNode())); } template ValueType InternalAdd::getValue() const { - return static_cast(Cudd_V(this->getCuddAdd().getNode())); + return storm::utility::convertNumber(Cudd_V(this->getCuddAdd().getNode())); } template @@ -403,7 +403,7 @@ namespace storm { int* cube; double value; DdGen* generator = this->getCuddAdd().FirstCube(&cube, &value); - return AddIterator(fullDdManager, generator, cube, value, (Cudd_IsGenEmpty(generator) != 0), &metaVariables, enumerateDontCareMetaVariables); + return AddIterator(fullDdManager, generator, cube, storm::utility::convertNumber(value), (Cudd_IsGenEmpty(generator) != 0), &metaVariables, enumerateDontCareMetaVariables); } template @@ -504,7 +504,7 @@ namespace storm { // If we are at the maximal level, the value to be set is stored as a constant in the DD. if (currentLevel == maxLevel) { ValueType& targetValue = targetVector[offsets != nullptr ? (*offsets)[currentOffset] : currentOffset]; - targetValue = function(targetValue, Cudd_V(dd)); + targetValue = function(targetValue, storm::utility::convertNumber(Cudd_V(dd))); } else if (ddVariableIndices[currentLevel] < Cudd_NodeReadIndex(dd)) { // If we skipped a level, we need to enumerate the explicit entries for the case in which the bit is set // and for the one in which it is not set. @@ -590,7 +590,7 @@ namespace storm { // If we are at the maximal level, the value to be set is stored as a constant in the DD. if (currentRowLevel + currentColumnLevel == maxLevel) { if (generateValues) { - columnsAndValues[rowIndications[rowGroupOffsets[currentRowOffset]]] = storm::storage::MatrixEntry(currentColumnOffset, Cudd_V(dd)); + columnsAndValues[rowIndications[rowGroupOffsets[currentRowOffset]]] = storm::storage::MatrixEntry(currentColumnOffset, storm::utility::convertNumber(Cudd_V(dd))); } ++rowIndications[rowGroupOffsets[currentRowOffset]]; } else { diff --git a/src/storm/utility/KwekMehlhorn.cpp b/src/storm/utility/KwekMehlhorn.cpp index ec81a3357..070115c72 100644 --- a/src/storm/utility/KwekMehlhorn.cpp +++ b/src/storm/utility/KwekMehlhorn.cpp @@ -43,8 +43,8 @@ namespace storm { } double powerOfTen = std::pow(10, precision); - double truncated = storm::utility::trunc(value * powerOfTen); - return std::make_pair(truncated, powerOfTen); + auto truncated = storm::utility::trunc(value * powerOfTen); + return std::make_pair(storm::utility::convertNumber::IntegerType>(truncated), storm::utility::convertNumber::IntegerType>(powerOfTen)); } template diff --git a/src/storm/utility/constants.cpp b/src/storm/utility/constants.cpp index 278852f90..cd6556fed 100644 --- a/src/storm/utility/constants.cpp +++ b/src/storm/utility/constants.cpp @@ -335,6 +335,15 @@ namespace storm { return NumberTraits::IntegerType(static_cast(number)); } + template<> + typename NumberTraits::IntegerType convertNumber(double const& number){ + if (number < static_cast(std::numeric_limits::max())) { + return NumberTraits::IntegerType(static_cast(number)); + } else { + return carl::round(carl::rationalize(number)); + } + } + template<> ClnRationalNumber convertNumber(int_fast64_t const& number) { STORM_LOG_ASSERT(static_cast(number) == number, "Rationalizing failed, because the number is too large."); @@ -518,6 +527,11 @@ namespace storm { return NumberTraits::IntegerType(static_cast(number)); } + template<> + typename NumberTraits::IntegerType convertNumber(double const& number){ + return NumberTraits::IntegerType(number); + } + template<> GmpRationalNumber convertNumber(int_fast64_t const& number){ STORM_LOG_ASSERT(static_cast(number) == number, "Rationalizing failed, because the number is too large.");