diff --git a/DataTree.cc b/DataTree.cc index f95708e6f3c0d08d1a6ccf1c1872a55212c29087..629365fbd004bd2d3d39d11d8c39186d3f771e95 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -51,7 +51,7 @@ DataTree::~DataTree() } expr_t -DataTree::AddNonNegativeConstant(const string &value) throw (NumericalConstants::InvalidFloatingPointNumberException) +DataTree::AddNonNegativeConstant(const string &value) { int id = num_constants.AddNonNegativeConstant(value); diff --git a/DataTree.hh b/DataTree.hh index e616f9cfef86347f4c79b98a97d5ac94bb229833..17823d23f0c313ac84cfd307ef992338f4dbff55 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -110,7 +110,7 @@ public: }; //! Adds a non-negative numerical constant (possibly Inf or NaN) - expr_t AddNonNegativeConstant(const string &value) throw (NumericalConstants::InvalidFloatingPointNumberException); + expr_t AddNonNegativeConstant(const string &value); //! Adds a variable /*! The default implementation of the method refuses any lag != 0 */ virtual VariableNode *AddVariable(int symb_id, int lag = 0); diff --git a/NumericalConstants.cc b/NumericalConstants.cc index 6efe1fc06e01503efcf6f0f9858e74e858c1322a..dc2bd80f2a7d06b295afb8e7a990d3953defcd01 100644 --- a/NumericalConstants.cc +++ b/NumericalConstants.cc @@ -26,7 +26,7 @@ #include "NumericalConstants.hh" int -NumericalConstants::AddNonNegativeConstant(const string &iConst) throw (InvalidFloatingPointNumberException) +NumericalConstants::AddNonNegativeConstant(const string &iConst) { map<string, int>::const_iterator iter = numConstantsIndex.find(iConst); @@ -37,12 +37,10 @@ NumericalConstants::AddNonNegativeConstant(const string &iConst) throw (InvalidF mNumericalConstants.push_back(iConst); numConstantsIndex[iConst] = id; - errno = 0; double val = strtod(iConst.c_str(), NULL); - // We check that the number is valid (e.g. not like "1e-10000") - if (errno != 0) - throw InvalidFloatingPointNumberException(iConst); + /* Note that we allow underflows (will be converted to 0) and overflows (will + be converted to Inf), as MATLAB and Octave do. */ assert(val >= 0 || isnan(val)); // Check we have a positive constant or a NaN double_vals.push_back(val); diff --git a/NumericalConstants.hh b/NumericalConstants.hh index 0a54616a23fbacc27b7eb6134991c28ea09ef020..cb50b0cb47d556b3c714cd796700b894a4532002 100644 --- a/NumericalConstants.hh +++ b/NumericalConstants.hh @@ -37,15 +37,8 @@ private: //! Map matching constants to their id map<string, int> numConstantsIndex; public: - class InvalidFloatingPointNumberException - { - public: - const string fp; - InvalidFloatingPointNumberException(const string &fp_arg) : fp(fp_arg) {} - }; - //! Adds a non-negative constant (possibly Inf or NaN) and returns its ID - int AddNonNegativeConstant(const string &iConst) throw (InvalidFloatingPointNumberException); + int AddNonNegativeConstant(const string &iConst); //! Get a constant in string form string get(int ID) const; //! Get a constant in double form diff --git a/ParsingDriver.cc b/ParsingDriver.cc index a307855439ddda8316d7cfe84a88437202d3a271..75dc4daaaf67ac7f05c108ab2a3cf472c838dc9d 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -258,15 +258,7 @@ ParsingDriver::add_equation_tags(string *key, string *value) expr_t ParsingDriver::add_non_negative_constant(string *constant) { - expr_t id; - try - { - id = data_tree->AddNonNegativeConstant(*constant); - } - catch (NumericalConstants::InvalidFloatingPointNumberException &e) - { - error("Invalid floating point number: " + *constant); - } + expr_t id = data_tree->AddNonNegativeConstant(*constant); delete constant; return id; } @@ -747,17 +739,11 @@ void ParsingDriver::add_value(string *v) { expr_t id; - try - { - if (v->at(0) == '-') - id = data_tree->AddUMinus(data_tree->AddNonNegativeConstant(v->substr(1, string::npos))); - else - id = data_tree->AddNonNegativeConstant(*v); - } - catch (NumericalConstants::InvalidFloatingPointNumberException &e) - { - error("Invalid floating point number: " + *v); - } + + if (v->at(0) == '-') + id = data_tree->AddUMinus(data_tree->AddNonNegativeConstant(v->substr(1, string::npos))); + else + id = data_tree->AddNonNegativeConstant(*v); delete v; det_shocks_values.push_back(id); @@ -1004,17 +990,11 @@ void ParsingDriver::add_to_row_const(string *v) { expr_t id; - try - { - if (v->at(0) == '-') - id = data_tree->AddUMinus(data_tree->AddNonNegativeConstant(v->substr(1, string::npos))); - else - id = data_tree->AddNonNegativeConstant(*v); - } - catch (NumericalConstants::InvalidFloatingPointNumberException &e) - { - error("Invalid floating point number: " + *v); - } + + if (v->at(0) == '-') + id = data_tree->AddUMinus(data_tree->AddNonNegativeConstant(v->substr(1, string::npos))); + else + id = data_tree->AddNonNegativeConstant(*v); delete v; sigmae_row.push_back(id);