From 0e683d98cee9d25ad018cc145d62fbdbf5d280ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Tue, 17 Dec 2024 13:29:07 +0100 Subject: [PATCH] feat: enhance LookupKey with const isnan method and comparison operator --- src/Chemistry/SurrogateModels/LookupKey.hpp | 6 +++++- src/Chemistry/SurrogateModels/Rounding.hpp | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Chemistry/SurrogateModels/LookupKey.hpp b/src/Chemistry/SurrogateModels/LookupKey.hpp index 6e7b0681c..87c626f77 100644 --- a/src/Chemistry/SurrogateModels/LookupKey.hpp +++ b/src/Chemistry/SurrogateModels/LookupKey.hpp @@ -21,7 +21,7 @@ struct Lookup_SC_notation { return {SC_NOTATION_EXPONENT_MASK, SC_NOTATION_SIGNIFICANT_MASK}; } - constexpr bool isnan() { + constexpr bool isnan() const { return !!(exp == SC_NOTATION_EXPONENT_MASK && significant == SC_NOTATION_SIGNIFICANT_MASK); } @@ -35,6 +35,10 @@ union Lookup_Keyelement { return std::memcmp(this, &other, sizeof(Lookup_Keyelement)) == 0 ? true : false; } + + template bool operator>(const T &other) const { + return this->sc_notation.significant > other; + } }; class LookupKey : public std::vector { diff --git a/src/Chemistry/SurrogateModels/Rounding.hpp b/src/Chemistry/SurrogateModels/Rounding.hpp index 688ac4707..6656b8026 100644 --- a/src/Chemistry/SurrogateModels/Rounding.hpp +++ b/src/Chemistry/SurrogateModels/Rounding.hpp @@ -65,6 +65,14 @@ public: std::uint32_t signif) { Lookup_Keyelement new_val = value; + if (value.sc_notation.isnan()) { + return {.sc_notation = Lookup_SC_notation::nan()}; + } + + if (signif == 0) { + return {.sc_notation = {0, value > 0}}; + } + std::uint32_t diff_signif = static_cast( std::ceil(std::log10(std::abs(value.sc_notation.significant)))) -