summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pfunction.h
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-10-31 21:53:50 +0100
committer couriersud <couriersud@gmx.org>2019-10-31 21:53:50 +0100
commitc6b281685d16c02b83b1b0c89acae392ecf851ff (patch)
tree2cd979f919b39e1feeffbde0b22462db59a6492a /src/lib/netlist/plib/pfunction.h
parent6c075e602cf83b379b8fa2c981694134b679a538 (diff)
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.
Diffstat (limited to 'src/lib/netlist/plib/pfunction.h')
-rw-r--r--src/lib/netlist/plib/pfunction.h12
1 files changed, 8 insertions, 4 deletions
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 <typename NT>
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<double> &values) noexcept;
+ NT evaluate(const std::vector<NT> &values) noexcept;
private:
void compile_postfix(const std::vector<pstring> &inputs,
const std::vector<pstring> &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<double>(m_lfsr) / static_cast<double>(0xffffu);
+ return static_cast<NT>(m_lfsr) / static_cast<NT>(0xffffu);
}
std::vector<rpn_inst> 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<float>;
+ extern template struct pfunction<double>;
} // namespace plib