diff options
author | justanothercatgirl <sotov@twistea.su> | 2024-12-04 22:32:12 +0300 |
---|---|---|
committer | justanothercatgirl <sotov@twistea.su> | 2024-12-04 22:32:12 +0300 |
commit | 8269ece153d9f8d1a8a5fb7238adce6aa4226f99 (patch) | |
tree | da560c3866ac00ebb65699cb6bac0e199a877835 /libprakpp/include/prakcommon.hpp | |
parent | c031795880d2ff2d3b64864a4ba68280a91d21c3 (diff) |
added vtek7
Diffstat (limited to 'libprakpp/include/prakcommon.hpp')
-rw-r--r-- | libprakpp/include/prakcommon.hpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libprakpp/include/prakcommon.hpp b/libprakpp/include/prakcommon.hpp index 3035ff8..c9bced3 100644 --- a/libprakpp/include/prakcommon.hpp +++ b/libprakpp/include/prakcommon.hpp @@ -75,6 +75,24 @@ fequal(T x, T y, std::size_t ulps = 1) return std::fabs(x - y) <= ulps * std::ldexp(std::numeric_limits<T>::epsilon(), exp); } +template<typename T> +T sum(const std::vector<T> &args) { + T res{}; + for (const T& x : args) res += x; + return res; +} + +template<typename T> +T prod(const std::vector<T> &args) { + T res = 1; + for (const T& x : args) res *= x; + return res; +} + +template <std::floating_point T> +T hypot(const std::vector<T> &args) { + return std::sqrt(args[0]*args[0] + args[1]*args[1]); +} /// prints a vector template <typename T> |