diff options
-rw-r--r-- | src/lib/netlist/analog/nld_bjt.cpp | 6 | ||||
-rw-r--r-- | src/lib/netlist/analog/nld_generic_models.h | 12 | ||||
-rw-r--r-- | src/lib/netlist/analog/nld_mosfet.cpp | 8 | ||||
-rw-r--r-- | src/lib/netlist/analog/nld_opamps.cpp | 4 | ||||
-rw-r--r-- | src/lib/netlist/analog/nlid_twoterm.cpp | 1 | ||||
-rw-r--r-- | src/lib/netlist/devices/nld_74123.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_proxy.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_system.h | 6 | ||||
-rw-r--r-- | src/lib/netlist/nl_errstr.h | 2 | ||||
-rwxr-xr-x | src/lib/netlist/nl_setup.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/nltypes.h | 5 | ||||
-rw-r--r-- | src/lib/netlist/plib/pmath.h | 15 | ||||
-rw-r--r-- | src/lib/netlist/prg/nlwav.cpp | 2 |
13 files changed, 41 insertions, 26 deletions
diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index f0f8d713891..e5e8c64de25 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -176,8 +176,8 @@ namespace analog , m_RB(*this, "m_RB", true) , m_RC(*this, "m_RC", true) , m_BC(*this, "m_BC", true) - , m_gB(nlconst::magic(1e-9)) - , m_gC(nlconst::magic(1e-9)) + , m_gB(nlconst::cgmin()) + , m_gC(nlconst::cgmin()) , m_V(nlconst::zero()) , m_state_on(*this, "m_state_on", 0) { @@ -394,7 +394,7 @@ namespace analog NETLIB_UPDATE_TERMINALS(QBJT_EB) { - const nl_fptype polarity = nlconst::magic(qtype() == BJT_NPN ? 1.0 : -1.0); + const nl_fptype polarity(qtype() == BJT_NPN ? nlconst::one() : -nlconst::one()); m_gD_BE.update_diode(-m_D_EB.deltaV() * polarity); m_gD_BC.update_diode(-m_D_CB.deltaV() * polarity); diff --git a/src/lib/netlist/analog/nld_generic_models.h b/src/lib/netlist/analog/nld_generic_models.h index a87407e70d8..52862643ea2 100644 --- a/src/lib/netlist/analog/nld_generic_models.h +++ b/src/lib/netlist/analog/nld_generic_models.h @@ -223,10 +223,10 @@ namespace analog , m_Vcrit(nlconst::zero()) { set_param( - nlconst::magic(1e-15) - , nlconst::magic(1) + nlconst::np_Is() + , nlconst::one() , nlconst::magic(1e-15) - , nlconst::magic(300.0)); + , nlconst::T0()); //m_name = name; } //pstring m_name; @@ -252,7 +252,7 @@ namespace analog const nl_fptype old = std::max(nlconst::zero(), m_Vd()); const nl_fptype d = std::min(+fp_constants<nl_fptype>::DIODE_MAXDIFF(), nVd - old); const nl_fptype a = plib::abs(d) * m_VtInv; - m_Vd = old + nlconst::magic(d < 0 ? -1.0 : 1.0) * plib::log1p(a) * m_Vt; + m_Vd = old + plib::signum(d) * plib::log1p(a) * m_Vt; } else m_Vd = std::max(-fp_constants<nl_fptype>::DIODE_MAXDIFF(), nVd); @@ -314,7 +314,7 @@ namespace analog m_logIs = plib::log(Is); m_gmin = gmin; - m_Vt = n * temp * nlconst::k_b() / nlconst::Q_e(); + m_Vt = nlconst::np_VT(n, temp); m_VtInv = plib::reciprocal(m_Vt); #if USE_TEXTBOOK_DIODE @@ -331,7 +331,7 @@ namespace analog // ln(P/Is) = ln(V)+V/Vt ~= V - 1 + V/vt // V = (1+ln(P/Is))/(1 + 1/Vt) - m_Vcrit = (1.0 + plib::log(0.5 / m_Is)) / (1.0 + m_VtInv); + m_Vcrit = (nlconst::one() + plib::log(nlconst::half() / m_Is)) / (nlconst::one() + m_VtInv); //printf("Vcrit: %f\n", m_Vcrit); m_Icrit_p_Is = plib::exp(m_logIs + m_Vcrit * m_VtInv); //m_Icrit = plib::exp(m_logIs + m_Vcrit * m_VtInv) - m_Is; diff --git a/src/lib/netlist/analog/nld_mosfet.cpp b/src/lib/netlist/analog/nld_mosfet.cpp index 83f5c9dd7d8..db22297470a 100644 --- a/src/lib/netlist/analog/nld_mosfet.cpp +++ b/src/lib/netlist/analog/nld_mosfet.cpp @@ -200,7 +200,7 @@ namespace analog , m_lambda(nlconst::zero()) , m_Leff(nlconst::zero()) , m_CoxWL(nlconst::zero()) - , m_polarity(nlconst::magic(qtype() == FET_NMOS ? 1.0 : -1.0)) + , m_polarity(qtype() == FET_NMOS ? nlconst::one() : -nlconst::one()) , m_Cgb(nlconst::zero()) , m_Cgs(nlconst::zero()) , m_Cgd(nlconst::zero()) @@ -218,7 +218,7 @@ namespace analog connect(m_DG.P(), m_SD.N()); set_qtype((m_model.type() == "NMOS_DEFAULT") ? FET_NMOS : FET_PMOS); - m_polarity = nlconst::magic((qtype() == FET_NMOS) ? 1.0 : -1.0); + m_polarity = (qtype() == FET_NMOS ? nlconst::one() : -nlconst::one()); m_capmod = m_model.m_CAPMOD; // printf("capmod %d %g %g\n", m_capmod, (nl_fptype)m_model.m_VTO, m_polarity); @@ -448,9 +448,9 @@ namespace analog const nl_fptype k = nlconst::magic(3.5); // see "Circuit Simulation", page 185 nl_fptype d = (Vgs - m_Vgs); - Vgs = m_Vgs + plib::reciprocal(k) * nlconst::magic(d < 0 ? -1.0 : 1.0) * plib::log1p(k * plib::abs(d)); + Vgs = m_Vgs + plib::reciprocal(k) * plib::signum(d) * plib::log1p(k * plib::abs(d)); d = (Vgd - m_Vgd); - Vgd = m_Vgd + plib::reciprocal(k) * nlconst::magic(d < 0 ? -1.0 : 1.0) * plib::log1p(k * plib::abs(d)); + Vgd = m_Vgd + plib::reciprocal(k) * plib::signum(d) * plib::log1p(k * plib::abs(d)); m_Vgs = Vgs; m_Vgd = Vgd; diff --git a/src/lib/netlist/analog/nld_opamps.cpp b/src/lib/netlist/analog/nld_opamps.cpp index 8d4aec8ea29..232dcdf90d9 100644 --- a/src/lib/netlist/analog/nld_opamps.cpp +++ b/src/lib/netlist/analog/nld_opamps.cpp @@ -215,9 +215,9 @@ namespace netlist NETLIB_UPDATE(opamp) { - const nl_fptype cVt = nlconst::magic(0.0258 * 1.0); // * m_n; + const nl_fptype cVt = nlconst::np_VT(nlconst::one()); // * m_n; const nl_fptype cId = m_model.m_DAB; // 3 mA - const nl_fptype cVd = cVt * plib::log(cId / nlconst::magic(1e-15) + nlconst::one()); + const nl_fptype cVd = cVt * plib::log(cId / nlconst::np_Is() + nlconst::one()); m_VH.push(m_VCC() - m_model.m_VLH - cVd); m_VL.push(m_GND() + m_model.m_VLL + cVd); diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index c57d76c821e..e60f39ea202 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -124,7 +124,6 @@ namespace analog m_G = m_gmin; set_mat( m_G, -m_G, -m_I, -m_G, m_G, m_I); - //set(1.0/NETLIST_GMIN, 0.0, -5.0 * NETLIST_GMIN); } NETLIB_UPDATE_PARAM(L) diff --git a/src/lib/netlist/devices/nld_74123.cpp b/src/lib/netlist/devices/nld_74123.cpp index fac78954243..ba1eb4ff54d 100644 --- a/src/lib/netlist/devices/nld_74123.cpp +++ b/src/lib/netlist/devices/nld_74123.cpp @@ -29,7 +29,7 @@ namespace netlist , m_last_trig(*this, "m_last_trig", 0) , m_state(*this, "m_state", 0) , m_KP(*this, "m_KP", 0) - , m_K(*this, "K", nlconst::magic((m_dev_type == 4538) ? 1.0 : 0.4)) // CD4538 datasheet states PW=RC + , m_K(*this, "K", (m_dev_type == 4538) ? nlconst::one() : nlconst::magic(0.4)) // CD4538 datasheet states PW=RC , m_RI(*this, "RI", nlconst::magic(400.0)) // around 250 for HC series, 400 on LS/TTL, estimated from datasheets { if ((m_dev_type != 9602) && (m_dev_type != 4538) ) diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index 5ba505cd03d..61b11cddff9 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -113,7 +113,7 @@ namespace devices private: - static constexpr const nl_fptype G_OFF = nlconst::magic(1e-9); + static constexpr const nl_fptype G_OFF = nlconst::cgmin(); logic_input_t m_I; analog::NETLIB_NAME(twoterm) m_RP; diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index cd830995156..b318ad05491 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -442,7 +442,7 @@ namespace devices , m_R(*this, "_R") , m_I(*this, "I") , m_RON(*this, "RON", nlconst::one()) - , m_ROFF(*this, "ROFF", nlconst::magic(1.0E99)) + , m_ROFF(*this, "ROFF", nlconst::magic(1.0E20)) , m_last_state(*this, "m_last_state", 0) { register_subalias("1", m_R.P()); @@ -493,8 +493,8 @@ namespace devices , m_R1(*this, "_R1") , m_R2(*this, "_R2") , m_I(*this, "I") - , m_GON(*this, "GON", nlconst::magic(1e9)) - , m_GOFF(*this, "GOFF", nlconst::magic(1e9)) + , m_GON(*this, "GON", nlconst::magic(1e9)) // FIXME: all switches should have some on value + , m_GOFF(*this, "GOFF", nlconst::cgmin()) , m_last_state(*this, "m_last_state", 0) , m_FAMILY(*this, "FAMILY", "FAMILY(TYPE=TTL)") , m_power_pins(*this) diff --git a/src/lib/netlist/nl_errstr.h b/src/lib/netlist/nl_errstr.h index 6202ca6f695..78512156293 100644 --- a/src/lib/netlist/nl_errstr.h +++ b/src/lib/netlist/nl_errstr.h @@ -81,7 +81,7 @@ namespace netlist PERRMSGV(MF_MODEL_ERROR_ON_PAIR_1, 1, "Model error on pair {1}") PERRMSGV(MF_MODEL_PARAMETERS_NOT_UPPERCASE_1_2, 2, "Model parameters should be uppercase:{1} {2}") PERRMSGV(MF_ENTITY_1_NOT_FOUND_IN_MODEL_2, 2, "Entity {1} not found in model {2}") - PERRMSGV(MF_UNKNOWN_NUMBER_FACTOR_IN_1, 1, "Unknown number factor in: {1}") + PERRMSGV(MF_UNKNOWN_NUMBER_FACTOR_IN_2, 2, "Unknown number factor in: {1}:{2}") PERRMSGV(MF_MODEL_NUMBER_CONVERSION_ERROR, 4, "Can't convert {1}={2} to {3} for model {4}") PERRMSGV(MF_NOT_FOUND_IN_SOURCE_COLLECTION, 1, "unable to find {1} in sources collection") diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 3ba4345267a..228ddf7c1c7 100755 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -1146,7 +1146,7 @@ nl_fptype models_t::value(const pstring &model, const pstring &entity) case 'a': factor = nlconst::magic(1e-18); break; // NOLINT default: if (*p < '0' || *p > '9') - throw nl_exception(MF_UNKNOWN_NUMBER_FACTOR_IN_1(entity)); + throw nl_exception(MF_UNKNOWN_NUMBER_FACTOR_IN_2(model, entity)); } if (factor != nlconst::one()) tmp = plib::left(tmp, tmp.size() - 1); diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h index cc0dac87f05..42ba576d0db 100644 --- a/src/lib/netlist/nltypes.h +++ b/src/lib/netlist/nltypes.h @@ -33,11 +33,12 @@ namespace netlist { using BC = plib::constants<T>; + static inline constexpr T cgmin() noexcept { return BC::magic(1e-9); } // NOLINT + static inline constexpr T np_VT(T n=BC::one(), T temp=BC::T0()) noexcept { return n * temp * BC::k_b() / BC::Q_e(); } - static inline constexpr T np_Is() noexcept - { return static_cast<T>(1e-15); } // NOLINT + static inline constexpr T np_Is() noexcept { return static_cast<T>(1e-15); } // NOLINT }; /// \brief nlconst_base struct specialized for nl_fptype. diff --git a/src/lib/netlist/plib/pmath.h b/src/lib/netlist/plib/pmath.h index 1271707a228..4b3f7d41431 100644 --- a/src/lib/netlist/plib/pmath.h +++ b/src/lib/netlist/plib/pmath.h @@ -242,6 +242,21 @@ namespace plib return std::trunc(v); } + /// \brief signum function + /// + /// \tparam T type of the argument + /// \param v argument + /// \param r optional argument, if given will return r and -r instead of 1 and -1 + /// \return signum(v) + /// + template <typename T> + static inline constexpr typename std::enable_if<std::is_floating_point<T>::value, T>::type + signum(T v, T r = static_cast<T>(1)) + { + constexpr const auto z(static_cast<T>(0)); + return (v > z) ? r : ((v < z) ? -r : v); + } + /// \brief pow function /// /// \tparam T1 type of the first argument diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index c8f0619a58b..ad3050ff798 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -511,7 +511,7 @@ private: void nlwav_app::convert_wav(std::ostream &ostrm) { - double dt = 1.0 / static_cast<double>(opt_rate()); + double dt = plib::reciprocal(static_cast<double>(opt_rate())); plib::unique_ptr<wavwriter> wo = plib::make_unique<wavwriter>(ostrm, opt_out() != "-", m_instrms.size(), opt_rate(), opt_amp()); plib::unique_ptr<aggregator> ago = plib::make_unique<aggregator>(m_instrms.size(), dt, aggregator::callback_type(&wavwriter::process, wo.get())); |