2008-02-03 11:28:36 +01:00
|
|
|
/*
|
2013-06-12 16:42:09 +02:00
|
|
|
* Copyright (C) 2003-2012 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
|
|
|
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-06-28 13:20:45 +02:00
|
|
|
#include <cstdlib>
|
2009-04-28 18:21:39 +02:00
|
|
|
#include <cassert>
|
2009-05-07 10:50:59 +02:00
|
|
|
#include <cerrno>
|
2009-04-29 13:05:40 +02:00
|
|
|
#include <cmath>
|
2008-02-03 11:28:36 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#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
|
|
|
{
|
2009-04-29 13:05:40 +02:00
|
|
|
map<string, int>::const_iterator iter = numConstantsIndex.find(iConst);
|
2009-04-28 18:21:39 +02:00
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
if (iter != numConstantsIndex.end())
|
|
|
|
return iter->second;
|
|
|
|
|
2018-06-04 15:03:26 +02:00
|
|
|
auto id = (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
|
|
|
|
{
|
2009-04-28 18:21:39 +02:00
|
|
|
assert(ID >= 0 && ID < (int) mNumericalConstants.size());
|
|
|
|
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
|
|
|
{
|
2009-04-29 13:05:40 +02:00
|
|
|
assert(ID >= 0 && ID < (int) double_vals.size());
|
2009-12-16 18:13:23 +01:00
|
|
|
return (double_vals[ID]);
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|