From 320bf2f0155edd67557a3042403eeb843b90a41d Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Sun, 9 Mar 2025 23:15:32 +0300 Subject: added 219 --- libprakpp/include/prakcommon.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'libprakpp/include/prakcommon.hpp') diff --git a/libprakpp/include/prakcommon.hpp b/libprakpp/include/prakcommon.hpp index 47c793c..074e290 100644 --- a/libprakpp/include/prakcommon.hpp +++ b/libprakpp/include/prakcommon.hpp @@ -44,6 +44,16 @@ typedef long double _f64; #define SUBSCR_OPRTR operator() #endif +#ifndef ENDCHAR +# define ENDCHAR '\n' +#endif +#define var(v) << #v " = " << v << ENDCHAR + +#define FOR_EACH(fn, first, ...) fn(first) __VA_OPT__(FOR_EACH_AGAIN(fn, __VA_ARGS__)) +#define FOR_EACH_AGAIN(fn, ...) FOR_EACH(fn, __VA_ARGS__) +#define APPLY_VARS(...) FOR_EACH(var, __VA_ARGS__) +#define vars(...) APPLY_VARS(__VA_ARGS__) + template using function_t = std::function &)>; @@ -97,7 +107,7 @@ struct align_alloc : public std::allocator { constexpr void deallocate( T* p, std::size_t n ) { ::operator delete(p, std::align_val_t{64}); } -};; +}; /// alias prak::vector that is the same as std::vector, but uses aligned allocator template @@ -106,9 +116,11 @@ using vector = std::vector>; /// prak value / pair value: a value with an error template struct pvalue { T val, err; }; +template struct pvalue operator^(const struct pvalue &v, const T &a) { return {std::pow(v.val, a), a * std::pow(v.val, a-1) * v.err}; } template struct pvalue operator*(const struct pvalue &v, const T &a) { return {v.val * a, v.err * a}; } template struct pvalue operator*(const T &a, const struct pvalue &v) { return {v.val * a, v.err * a}; } template struct pvalue operator*(const struct pvalue &a, const struct pvalue &b) { return {a.val * b.val, a.val * b.val * std::hypot(a.err/a.val, b.err/b.val)}; } +template struct pvalue operator/(const T &a, const struct pvalue &v) { return {a / v.val, a * v.err / (v.val * v.val)}; } template struct pvalue operator/(const struct pvalue &v, const T &a) { return {v.val / a, v.err / a}; } template struct pvalue operator/(const struct pvalue &a, const struct pvalue &b) { return {a.val / b.val, a.val / b.val * std::hypot(a.err/a.val, b.err/b.val)}; } template struct pvalue operator+(const struct pvalue &a, const struct pvalue &b) { return {a.val + b.val, std::hypot(a.err, b.err)}; } -- cgit v1.2.3-70-g09d2