summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pmath.h
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2020-05-01 15:21:01 +0200
committer couriersud <couriersud@gmx.org>2020-05-01 15:21:01 +0200
commit40f8f99f9ae8a1dd709ef8e0cca488f533d22d41 (patch)
treecfdcbc5d58eb6e2294cf09a4c55d0b7cdcf99885 /src/lib/netlist/plib/pmath.h
parent644e330b71acc10f46c632b30c81fc08ad602656 (diff)
netlist: Removed more magic numbers from the code. (nw)
Diffstat (limited to 'src/lib/netlist/plib/pmath.h')
-rw-r--r--src/lib/netlist/plib/pmath.h15
1 files changed, 15 insertions, 0 deletions
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