2008-02-03 11:28:36 +01:00
|
|
|
/*
|
2019-12-16 19:42:59 +01:00
|
|
|
* Copyright © 2003-2019 Dynare Team
|
2008-02-03 11:28:36 +01:00
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-06-09 16:52:20 +02:00
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-02-03 11:28:36 +01:00
|
|
|
*/
|
|
|
|
|
2008-06-28 13:20:45 +02:00
|
|
|
#include <cstdlib>
|
2009-04-28 18:21:39 +02:00
|
|
|
#include <cassert>
|
2009-04-29 13:05:40 +02:00
|
|
|
#include <cmath>
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
|
|
#include "NumericalConstants.hh"
|
|
|
|
|
|
|
|
int
|
2012-07-12 12:46:22 +02:00
|
|
|
NumericalConstants::AddNonNegativeConstant(const string &iConst)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2019-12-16 19:42:59 +01:00
|
|
|
if (auto iter = numConstantsIndex.find(iConst);
|
|
|
|
iter != numConstantsIndex.end())
|
2008-02-03 11:28:36 +01:00
|
|
|
return iter->second;
|
|
|
|
|
2019-04-23 11:07:32 +02:00
|
|
|
auto id = static_cast<int>(mNumericalConstants.size());
|
2008-02-03 11:28:36 +01:00
|
|
|
mNumericalConstants.push_back(iConst);
|
|
|
|
numConstantsIndex[iConst] = id;
|
2009-04-29 13:05:40 +02:00
|
|
|
|
2012-07-12 12:46:22 +02:00
|
|
|
/* Note that we allow underflows (will be converted to 0) and overflows (will
|
2018-07-04 14:52:37 +02:00
|
|
|
be converted to Inf), as MATLAB and Octave do. As a consequence, we
|
|
|
|
cannot use std::stod() here, since it does not allow distinguishing
|
|
|
|
between underflow and overflow. */
|
|
|
|
double val = strtod(iConst.c_str(), nullptr);
|
2011-02-16 11:08:40 +01:00
|
|
|
|
2009-04-29 13:05:40 +02:00
|
|
|
assert(val >= 0 || isnan(val)); // Check we have a positive constant or a NaN
|
|
|
|
double_vals.push_back(val);
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
NumericalConstants::get(int ID) const
|
|
|
|
{
|
2019-04-23 11:07:32 +02:00
|
|
|
assert(ID >= 0 && ID < static_cast<int>(mNumericalConstants.size()));
|
2009-04-28 18:21:39 +02:00
|
|
|
return mNumericalConstants[ID];
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2009-04-29 13:05:40 +02:00
|
|
|
NumericalConstants::getDouble(int ID) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2019-04-23 11:07:32 +02:00
|
|
|
assert(ID >= 0 && ID < static_cast<int>(double_vals.size()));
|
2009-12-16 18:13:23 +01:00
|
|
|
return (double_vals[ID]);
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|