From 3c5c609e273bde33643c900e58368ea02a4d4101 Mon Sep 17 00:00:00 2001 From: JK Date: Thu, 9 Feb 2017 10:55:45 +0100 Subject: [PATCH] utility/cli.cpp, parseConstantDefinitionString: do constants parsing using rational number (exact) Uses convertNumber to obtain a rational number for double constants. Additionally, improve error message if something goes wrong during conversion. --- src/storm/utility/cli.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/storm/utility/cli.cpp b/src/storm/utility/cli.cpp index d7606149b..4798fd531 100644 --- a/src/storm/utility/cli.cpp +++ b/src/storm/utility/cli.cpp @@ -1,6 +1,7 @@ #include "storm/utility/cli.h" #include "storm/utility/macros.h" +#include "storm/utility/constants.h" #include "storm/exceptions/WrongFormatException.h" namespace storm { @@ -52,8 +53,12 @@ namespace storm { int_fast64_t integerValue = std::stoi(value); constantDefinitions[variable] = manager.integer(integerValue); } else if (variable.hasRationalType()) { - double doubleValue = std::stod(value); - constantDefinitions[variable] = manager.rational(doubleValue); + try { + storm::RationalNumber rationalValue = storm::utility::convertNumber(value); + constantDefinitions[variable] = manager.rational(rationalValue); + } catch (std::exception& e) { + STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Illegal constant definition string '" << constantName << "=" << value << "': " << e.what()); + } } } else { STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Illegal constant definition string: unknown undefined constant '" << constantName << "'.");