netlist: convert constexpr constants into constexpr inline funcs. (nw)

This commit is contained in:
couriersud 2019-11-01 01:50:11 +01:00
parent 58c420eeb7
commit a9d7e55ac2
3 changed files with 18 additions and 17 deletions

View File

@ -158,12 +158,12 @@ namespace analog
//printf("%s: %g %g\n", m_name.c_str(), nVd, (nl_fptype) m_Vd); //printf("%s: %g %g\n", m_name.c_str(), nVd, (nl_fptype) m_Vd);
if (nVd > m_Vcrit) if (nVd > m_Vcrit)
{ {
const nl_fptype d = std::min(+fp_constants<nl_fptype>::DIODE_MAXDIFF, nVd - m_Vd); const nl_fptype d = std::min(+fp_constants<nl_fptype>::DIODE_MAXDIFF(), nVd - m_Vd);
const nl_fptype a = std::abs(d) * m_VtInv; const nl_fptype a = std::abs(d) * m_VtInv;
m_Vd = m_Vd + (d < 0 ? -1.0 : 1.0) * std::log1p(a) * m_Vt; m_Vd = m_Vd + (d < 0 ? -1.0 : 1.0) * std::log1p(a) * m_Vt;
} }
else else
m_Vd = std::max(-fp_constants<nl_fptype>::DIODE_MAXDIFF, nVd); m_Vd = std::max(-fp_constants<nl_fptype>::DIODE_MAXDIFF(), nVd);
//m_Vd = nVd; //m_Vd = nVd;
if (m_Vd < m_Vmin) if (m_Vd < m_Vmin)
@ -189,7 +189,7 @@ namespace analog
else /* log stepping should already be done in mosfet */ else /* log stepping should already be done in mosfet */
{ {
m_Vd = nVd; m_Vd = nVd;
IseVDVt = std::exp(std::min(+fp_constants<nl_fptype>::DIODE_MAXVOLT, m_logIs + m_Vd * m_VtInv)); IseVDVt = std::exp(std::min(+fp_constants<nl_fptype>::DIODE_MAXVOLT(), m_logIs + m_Vd * m_VtInv));
m_Id = IseVDVt - m_Is; m_Id = IseVDVt - m_Is;
m_G = IseVDVt * m_VtInv + m_gmin; m_G = IseVDVt * m_VtInv + m_gmin;
} }
@ -213,10 +213,10 @@ namespace analog
} }
nl_fptype I() const { return m_Id; } nl_fptype I() const noexcept { return m_Id; }
nl_fptype G() const { return m_G; } nl_fptype G() const noexcept { return m_G; }
nl_fptype Ieq() const { return (m_Id - m_Vd * m_G); } nl_fptype Ieq() const noexcept { return (m_Id - m_Vd * m_G); }
nl_fptype Vd() const { return m_Vd; } nl_fptype Vd() const noexcept { return m_Vd; }
/* owning object must save those ... */ /* owning object must save those ... */

View File

@ -124,11 +124,11 @@ namespace netlist
template <> template <>
struct fp_constants<double> struct fp_constants<double>
{ {
static constexpr const double DIODE_MAXDIFF = 1e100; static inline constexpr const double DIODE_MAXDIFF() noexcept { return 1e100; }
static constexpr const double DIODE_MAXVOLT = 300.0; static inline constexpr double DIODE_MAXVOLT() noexcept { return 300.0; }
static constexpr const double TIMESTEP_MAXDIFF = 1e100; static inline constexpr double TIMESTEP_MAXDIFF() noexcept { return 1e100; }
static constexpr const double TIMESTEP_MINDIV = 1e-60; static inline constexpr double TIMESTEP_MINDIV() noexcept { return 1e-60; }
}; };
/*! Specific constants for float floating point type /*! Specific constants for float floating point type
@ -136,11 +136,11 @@ namespace netlist
template <> template <>
struct fp_constants<float> struct fp_constants<float>
{ {
static constexpr const float DIODE_MAXDIFF = 1e5; static inline constexpr float DIODE_MAXDIFF() noexcept { return 1e5; }
static constexpr const float DIODE_MAXVOLT = 30.0; static inline constexpr float DIODE_MAXVOLT() noexcept { return 30.0; }
static constexpr const float TIMESTEP_MAXDIFF = 1e30f; static inline constexpr float TIMESTEP_MAXDIFF() noexcept { return 1e30f; }
static constexpr const float TIMESTEP_MINDIV = 1e-8f; static inline constexpr float TIMESTEP_MINDIV() noexcept { return 1e-8f; }
}; };
} // namespace netlist } // namespace netlist

View File

@ -429,7 +429,8 @@ namespace solver
//const nl_fptype DD_n = (n->Q_Analog() - t->m_last_V); //const nl_fptype DD_n = (n->Q_Analog() - t->m_last_V);
// avoid floating point exceptions // avoid floating point exceptions
const nl_fptype DD_n = std::max(-fp_constants<nl_fptype>::TIMESTEP_MAXDIFF, std::min(+fp_constants<nl_fptype>::TIMESTEP_MAXDIFF,(t.getV() - m_last_V[k]))); const nl_fptype DD_n = std::max(-fp_constants<nl_fptype>::TIMESTEP_MAXDIFF(),
std::min(+fp_constants<nl_fptype>::TIMESTEP_MAXDIFF(),(t.getV() - m_last_V[k])));
const nl_fptype hn = cur_ts; const nl_fptype hn = cur_ts;
//printf("%g %g %g %g\n", DD_n, hn, t.m_DD_n_m_1, t.m_h_n_m_1); //printf("%g %g %g %g\n", DD_n, hn, t.m_DD_n_m_1, t.m_h_n_m_1);
@ -438,7 +439,7 @@ namespace solver
m_h_n_m_1[k] = hn; m_h_n_m_1[k] = hn;
m_DD_n_m_1[k] = DD_n; m_DD_n_m_1[k] = DD_n;
if (std::fabs(DD2) > fp_constants<nl_fptype>::TIMESTEP_MINDIV) // avoid div-by-zero if (std::fabs(DD2) > fp_constants<nl_fptype>::TIMESTEP_MINDIV()) // avoid div-by-zero
new_net_timestep = std::sqrt(m_params.m_dynamic_lte / std::fabs(plib::constants<nl_fptype>::cast(0.5)*DD2)); new_net_timestep = std::sqrt(m_params.m_dynamic_lte / std::fabs(plib::constants<nl_fptype>::cast(0.5)*DD2));
else else
new_net_timestep = m_params.m_max_timestep; new_net_timestep = m_params.m_max_timestep;