From c6b281685d16c02b83b1b0c89acae392ecf851ff Mon Sep 17 00:00:00 2001 From: couriersud Date: Thu, 31 Oct 2019 21:53:50 +0100 Subject: netlist: Compile with float/double floating point. [Couriersud] Added ability to compile using float instead of double. Specifically the the solver as well as the infrastructure now can have their own floating point type. Currently this is only an academic exercise since numerically demanding circuits like kidniki only work with double/double support. Using float here is pushing numerical stability over the limits. The long term design goal is too have the matrix type (double/float) being a parameter. --- src/lib/netlist/plib/pfunction.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/lib/netlist/plib/pfunction.h') diff --git a/src/lib/netlist/plib/pfunction.h b/src/lib/netlist/plib/pfunction.h index 8c6d71f33e4..31ff9475fae 100644 --- a/src/lib/netlist/plib/pfunction.h +++ b/src/lib/netlist/plib/pfunction.h @@ -21,7 +21,9 @@ namespace plib { /*! Class providing support for evaluating expressions * + * @tparam NT Number type, should be float or double */ + template class pfunction { enum rpn_cmd @@ -42,7 +44,7 @@ namespace plib { { rpn_inst() : m_cmd(ADD), m_param(0.0) { } rpn_cmd m_cmd; - double m_param; + NT m_param; }; public: /*! Constructor with state saving support @@ -91,20 +93,20 @@ namespace plib { * @param values for input variables, e.g. {1.1, 2.2} * @return value of expression */ - double evaluate(const std::vector &values) noexcept; + NT evaluate(const std::vector &values) noexcept; private: void compile_postfix(const std::vector &inputs, const std::vector &cmds, const pstring &expr); - double lfsr_random() noexcept + NT lfsr_random() noexcept { std::uint16_t lsb = m_lfsr & 1; m_lfsr >>= 1; if (lsb) m_lfsr ^= 0xB400u; // taps 15, 13, 12, 10 - return static_cast(m_lfsr) / static_cast(0xffffu); + return static_cast(m_lfsr) / static_cast(0xffffu); } std::vector m_precompiled; //!< precompiled expression @@ -112,6 +114,8 @@ namespace plib { std::uint16_t m_lfsr; //!< lfsr used for generating random numbers }; + extern template struct pfunction; + extern template struct pfunction; } // namespace plib -- cgit v1.2.3