From 11bb3bce732da7333512913a6568daa4b3f06aaa Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 20 Jul 2026 23:12:24 +0200 Subject: [PATCH] Parameters: draft a family of pre-conditioning operations - we need a generic operation to clamp to the smaller value domain - furthermore we need a virtual function to apply a type specific limiter __TODO__: this draft does not handle properly signed vs. unsigned types --- src/lib/par/domain.hpp | 77 ++++++++++++-- tests/lib/par/parameter-domain-test.cpp | 25 +++++ wiki/thinkPad.ichthyo.mm | 135 +++++++++++++++++++++++- 3 files changed, 227 insertions(+), 10 deletions(-) diff --git a/src/lib/par/domain.hpp b/src/lib/par/domain.hpp index fbf15c47a..086a8f391 100644 --- a/src/lib/par/domain.hpp +++ b/src/lib/par/domain.hpp @@ -38,11 +38,20 @@ //#include "lib/meta/typelist-util.hpp" #include "lib/meta/generator.hpp" #include "lib/meta/trait.hpp" +#include "lib/util.hpp" + +#include +#include namespace lib { namespace par { + using std::same_as; + using std::floating_point; + using std::numeric_limits; + + struct ValBuff { /*placeholder*/ }; template @@ -116,6 +125,8 @@ namespace par { public: virtual ~Domain(); ///< this is an interface + virtual void applyLimit (ValBuff&) =0; + protected: }; @@ -131,7 +142,7 @@ _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") template - struct TypeSetup + struct DomainSetup { template @@ -148,33 +159,83 @@ _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") template class BaseDomain - : public TypeSetup::TypeHandlerChain + : public DomainSetup::TypeHandlerChain { public: + void applyLimit (ValBuff&) override; }; /* ===== type conversion details ===== */ - + + template + concept sub_domain = std::signed_integral != std::signed_integral + or std::numeric_limits::max() < std::numeric_limits::max() + or std::numeric_limits::lowest() > std::numeric_limits::lowest() + ; + + /** generic helper to conform into a common value domain + * @tparam SUB the implied target value domain + * @tparam BAS source data type + * @return a value in source data type, + * yet conformed into the target data range + */ + template + inline constexpr BAS + preClamp (BAS const& value) + { + return value; + } + + /** special case: clamp the source value into the target value domain */ + template requires sub_domain + inline constexpr BAS + preClamp (BAS const& rawVal) + { + auto upperBound = numeric_limits::max(); + auto lowerBound = numeric_limits::lowest(); + return util::limited (lowerBound, rawVal, upperBound); + } + + /** special case: trigger a bool at the 0.5 level */ + template B, floating_point F> + inline constexpr F + preClamp (F const& rawVal) + { + return 0.5 < rawVal? F{1} : F{0}; + } + + + template + inline void + BaseDomain::applyLimit (ValBuff& valBuff) + { + X& val{asValue (valBuff)}; + val = preClamp (val); + } + + + template template inline void - TypeSetup::TypeHandlerImpl::extractAs (X& targetVal, ValBuff const& valBuff) + DomainSetup::TypeHandlerImpl::extractAs (X& targetVal, ValBuff const& valBuff) { - if constexpr (std::is_assignable_v) + if constexpr (std::is_assignable_v) { - targetVal = asValue (valBuff); + targetVal = preClamp (asValue (valBuff)); } else - if constexpr (std::is_constructible_v) + if constexpr (std::is_constructible_v) { targetVal.~X(); - new(&targetVal) X (asValue (valBuff)); + new(&targetVal) X (preClamp (asValue (valBuff))); } else static_assert (!sizeof(X), "this type conversion is not supported"); } + }} // namespace lib::par #endif /*LIB_PAR_DOMAIN_H*/ diff --git a/tests/lib/par/parameter-domain-test.cpp b/tests/lib/par/parameter-domain-test.cpp index 8a9cbee24..97ad9d4b5 100644 --- a/tests/lib/par/parameter-domain-test.cpp +++ b/tests/lib/par/parameter-domain-test.cpp @@ -70,6 +70,7 @@ namespace test{ { seedRand(); basics(); + verify_valueLimits(); verify_valueAccess(); } @@ -80,6 +81,30 @@ namespace test{ } + void + verify_valueLimits() + { +SHOW_EXPR(preClamp (23)) +SHOW_EXPR(preClamp (-55)) +SHOW_EXPR(preClamp (23)) +SHOW_EXPR(preClamp (-55)) +SHOW_EXPR((sub_domain)) +SHOW_EXPR((sub_domain)) +SHOW_EXPR((sub_domain)) +SHOW_EXPR(std::numeric_limits::max()) +SHOW_EXPR(std::numeric_limits::max()) +SHOW_EXPR(std::numeric_limits::lowest()) +SHOW_EXPR(std::numeric_limits::lowest()) +// concept sub_domain = std::numeric_limits::max() < std::numeric_limits::max() +// or std::numeric_limits::lowest() > std::numeric_limits::lowest() +//SHOW_EXPR(std::numeric_limits::lowest() > std::numeric_limits::lowest()) +//SHOW_EXPR(abs(std::numeric_limits::lowest()) < (std::numeric_limits::lowest())) + +SHOW_EXPR(preClamp (INT64_MAX)) +SHOW_EXPR(preClamp (INT64_MIN)) + } + + void verify_valueAccess() { diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index b899cb9c8..a529b4234 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -82211,7 +82211,9 @@ - + + + @@ -82971,7 +82973,7 @@ - + @@ -83040,6 +83042,131 @@ + + + + + + + + + + + + + + + +

+ das ist implizites Standard-Verhalten von C++ in praktisch jedem Ausdruck und Funktionsaufruf +

+ +
+
+
+ + + + +
+ + + + + +

+ das ist die zweite Hälfte des Domain-Begriffs +

+ +
+ + + + +

+ Basis ist ein Typ als Grundgesammtheit +

+ +
+
+ + + + + +

+ z.B. Farben +

+ +
+ + + + + +

+ naiver Weise dachte ich erst, eine Domain ist lediglich ein Teilintervall einer BaseDomain. Tja zu früh gefreut +

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + +

+ sonst geht der nachfolgende Vergleich für die untere Schwelle ganz glorreich in die Hose, schönen Gruß vom uint(-1) +

+ +
+ +
+
+ + + +
+ + + + + + + +
+
+ + + + + +

+ wir wollen explizit kein uint(-1) haben +

+ +
+ +
@@ -184807,6 +184934,10 @@ class Something
+ + + +