From 89d26d5d0e8ff2b026cc99606868699f6fcc08db Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Mon, 18 Nov 2024 23:40:21 +0300 Subject: added tempalte --- libprakipp/include/prakcommon.hpp | 94 --------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 libprakipp/include/prakcommon.hpp (limited to 'libprakipp/include/prakcommon.hpp') diff --git a/libprakipp/include/prakcommon.hpp b/libprakipp/include/prakcommon.hpp deleted file mode 100644 index 5fee864..0000000 --- a/libprakipp/include/prakcommon.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -#include -#include -#include - -#if defined(_MSC_VER) || !defined(__cpp_multidimensional_subscript) || __cplusplus < 202110L -#warning "can not use multidimentional subscript operator: falling back to `operator()`" -#undef MDSUBSCRIPT -#else -#define MDSUBSCRIPT -#endif - -#ifdef NO_MDSUBSCRIPT -#undef MDSUBSCRIPT -#endif - -#ifdef MDSUBSCRIPT - #define SUBSCR_OPN [ - #define SUBSCR_CLS ] - #define SUBSCR_OPRTR operator[] -#else - #define SUBSCR_OPN ( - #define SUBSCR_CLS ) - #define SUBSCR_OPRTR operator() -#endif - -namespace prak { - -/// stolen from [cppreference.com](https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon) -/// Compares 2 floating-point values up to `ulps` ULPS (units in the last place) -template -std::enable_if_t::is_integer, bool> -fequal(T x, T y, std::size_t ulps = 1) -{ - // Since `epsilon()` is the gap size (ULP, unit in the last place) - // of floating-point numbers in interval [1, 2), we can scale it to - // the gap size in interval [2^e, 2^{e+1}), where `e` is the exponent - // of `x` and `y`. - - // If `x` and `y` have different gap sizes (which means they have - // different exponents), we take the smaller one. Taking the bigger - // one is also reasonable, I guess. - const T m = std::min(std::fabs(x), std::fabs(y)); - - // Subnormal numbers have fixed exponent, which is `min_exponent - 1`. - const int exp = m < std::numeric_limits::min() - ? std::numeric_limits::min_exponent - 1 - : std::ilogb(m); - - // We consider `x` and `y` equal if the difference between them is - // within `n` ULPs. - return std::fabs(x - y) <= ulps * std::ldexp(std::numeric_limits::epsilon(), exp); -} - - -/// prints a vector -template -void printv(const T &vec) { - std::cout << "std::vector { "; - for (const auto &x : vec) { - std::cout << x << ' '; - } - std::cout << '}' << std::endl; -} - -/// An allocator that aligns memory to 64 bytes. Needed for AVX instructions. -/// C++17 required for std::align_val_t -template -struct align_alloc : public std::allocator { - constexpr T* allocate( std::size_t n ) { - return static_cast(::operator new(sizeof (T) * n, std::align_val_t{64})); - } - - 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 -using vector = std::vector>; - -/// prak value / pair value: a value with an error -template -struct pvalue { T val, err; }; - -template -std::ostream &operator<<(std::ostream &os, const struct pvalue &p) { - /* return os << "value {" << p.val << "±" << p.err << "}"; */ - return os << p.val << "±" << p.err; -} - -} // namespace prak -- cgit v1.2.3-70-g09d2