From 4f8a8e8042ac66d693bcf7417a0d0eaac0dd9b17 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 21 Sep 2026 01:05:53 +0200 Subject: [PATCH] Library: better short-hand name for long double As with all those C++ base types, unfortunately they are giving you only rough size guarantees. For Lumiera, I defined short hand names some time ago, notably because the explicit long X and short X qualifiers do not work with ''constructor syntax'' for direct conversions. But I choose the name `f128` at that time -- which might raise ill-guided expectations, since the `long double` is not that long on relevant linux 64bit platforms; it can just hold 64bit of mantissa at least however. As replacement, I'll use `lflo` now, because it has also 4 letters, looks somewhat weird (and thus catches attention) and points into the right direction. I considered `lfloat` as alternative, but that looks too much like `float`, visually... --- src/lib/format-obj.cpp | 4 ++-- src/lib/format-obj.hpp | 4 ++-- src/lib/integral.hpp | 4 ++-- src/lib/meta/util.hpp | 4 ++-- src/lib/par/type-handler.hpp | 5 ++++- src/lib/rational.hpp | 6 +++--- tests/lib/cyclic-wrap-test.cpp | 2 +- tests/lib/par/parameter-scale-test.cpp | 2 +- tests/lib/stat/data-csv-test.cpp | 2 +- tests/vault/mem/engine-buffer-manager-test.cpp | 4 ++-- 10 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lib/format-obj.cpp b/src/lib/format-obj.cpp index 676a4713f..9341f7a7c 100644 --- a/src/lib/format-obj.cpp +++ b/src/lib/format-obj.cpp @@ -363,11 +363,11 @@ namespace util { string showDecimal (double val) noexcept { return showFloatingPoint (val, PRECISION_DECIMAL); } string showDecimal (float val) noexcept { return showFloatingPoint (val, PRECISION_DECIMAL); } - string showDecimal (f128 val) noexcept { return showFloatingPoint (val, PRECISION_DECIMAL); } + string showDecimal (lflo val) noexcept { return showFloatingPoint (val, PRECISION_DECIMAL); } string showComplete (double val) noexcept { return showFloatingPoint (val, PRECISION_COMPLETE); } string showComplete (float val) noexcept { return showFloatingPoint (val, PRECISION_COMPLETE); } - string showComplete (f128 val) noexcept { return showFloatingPoint (val, PRECISION_COMPLETE); } + string showComplete (lflo val) noexcept { return showFloatingPoint (val, PRECISION_COMPLETE); } string diff --git a/src/lib/format-obj.hpp b/src/lib/format-obj.hpp index 842a26ff6..1041466b6 100644 --- a/src/lib/format-obj.hpp +++ b/src/lib/format-obj.hpp @@ -93,10 +93,10 @@ namespace util { std::string showDecimal (double) noexcept; std::string showDecimal (float) noexcept; - std::string showDecimal (f128) noexcept; + std::string showDecimal (lflo) noexcept; std::string showComplete (double)noexcept; std::string showComplete (float) noexcept; - std::string showComplete (f128) noexcept; + std::string showComplete (lflo) noexcept; diff --git a/src/lib/integral.hpp b/src/lib/integral.hpp index 7026d778f..d9f0a63f1 100644 --- a/src/lib/integral.hpp +++ b/src/lib/integral.hpp @@ -32,8 +32,8 @@ using llong = long long int; using ullong = unsigned long long int; using ushort = unsigned short int; -using f128 = long double; -static_assert(10 <= sizeof(f128)); +using lflo = long double; +static_assert(10 <= sizeof(lflo)); const uint LIFE_AND_UNIVERSE_4EVER = 42; diff --git a/src/lib/meta/util.hpp b/src/lib/meta/util.hpp index 7fb4967be..ad0cb8585 100644 --- a/src/lib/meta/util.hpp +++ b/src/lib/meta/util.hpp @@ -456,12 +456,12 @@ namespace util { /** show maximum reproducible decimal representation */ std::string showDecimal (double) noexcept; std::string showDecimal (float) noexcept; - std::string showDecimal (f128) noexcept; + std::string showDecimal (lflo) noexcept; /** show enough decimal digits to represent every distinct value */ std::string showComplete (double) noexcept; std::string showComplete (float) noexcept; - std::string showComplete (f128) noexcept; + std::string showComplete (lflo) noexcept; std::string showSize (size_t) noexcept; diff --git a/src/lib/par/type-handler.hpp b/src/lib/par/type-handler.hpp index 1df473758..6a6414dfa 100644 --- a/src/lib/par/type-handler.hpp +++ b/src/lib/par/type-handler.hpp @@ -180,11 +180,14 @@ _Pragma("GCC diagnostic pop") if constexpr (8 > sizeof(U)) return std::type_identity{}; else - return std::type_identity{}; + return std::type_identity{}; // no standard integral type can hold uint64_t's full range signed. // Expand to long double, which can hold 64bit without precision loss } } + + static_assert (64 <= std::numeric_limits::digits + ,"long double type can not represent uint64_t exactly"); } /** diff --git a/src/lib/rational.hpp b/src/lib/rational.hpp index ef310a31e..514e08f09 100644 --- a/src/lib/rational.hpp +++ b/src/lib/rational.hpp @@ -122,12 +122,12 @@ namespace util { u = 0!=u? u:1; auto [d,r] = util::iDiv (num, den); // round to smallest integer fraction, to shake off "number dust" - f128 const ROUND_ULP = 1 + 1/(f128(std::numeric_limits::max()) * 2); + lflo const ROUND_ULP = 1 + 1/(lflo(std::numeric_limits::max()) * 2); // construct approximation quantised to 1/u - f128 frac = f128(r) / den; + lflo frac = lflo(r) / den; int64_t res = d*u + int64_t(frac*u * ROUND_ULP); - ENSURE (abs (f128(res)/u - rational_cast(Rat{num,den})) <= 1.0/abs(u) + ENSURE (abs (lflo(res)/u - rational_cast(Rat{num,den})) <= 1.0/abs(u) ,"Requantisation error exceeded num=%li / den=%li -> res=%li / quant=%li" , num, den, res, u); return res; diff --git a/tests/lib/cyclic-wrap-test.cpp b/tests/lib/cyclic-wrap-test.cpp index 23071cf50..e737e037b 100644 --- a/tests/lib/cyclic-wrap-test.cpp +++ b/tests/lib/cyclic-wrap-test.cpp @@ -76,7 +76,7 @@ namespace test { verifyFloatTypes(); verifyFloatTypes(); - verifyFloatTypes(); + verifyFloatTypes(); } diff --git a/tests/lib/par/parameter-scale-test.cpp b/tests/lib/par/parameter-scale-test.cpp index 671696997..5d4132837 100644 --- a/tests/lib/par/parameter-scale-test.cpp +++ b/tests/lib/par/parameter-scale-test.cpp @@ -134,7 +134,7 @@ namespace test{ CHECK ( 15 == angleScale.conform(65535)); - Scale tinyScale = {.minVal=-f128(1)/100, .maxVal=f128(1)/100}; + Scale tinyScale = {.minVal=-lflo(1)/100, .maxVal=lflo(1)/100}; tinyScale.cyclicLim = util::limit_cyclicWrap(*tinyScale.maxVal - *tinyScale.minVal); CHECK (1e16 < tinyScale.cyclicLim); CHECK (tinyScale.isValid()); diff --git a/tests/lib/stat/data-csv-test.cpp b/tests/lib/stat/data-csv-test.cpp index a1aa0d4e6..7d19c05c0 100644 --- a/tests/lib/stat/data-csv-test.cpp +++ b/tests/lib/stat/data-csv-test.cpp @@ -224,7 +224,7 @@ namespace test{ CHECK (format4Csv(double(1) / 3) == "0.333333333333333"_expect ); CHECK (format4Csv(float(1) / 3) == "0.333333"_expect ); - CHECK (format4Csv(f128(1) / 3) == "0.333333333333333333"_expect); + CHECK (format4Csv(lflo(1) / 3) == "0.333333333333333333"_expect); CHECK (format4Csv(bool(1)) == "true"_expect ); CHECK (format4Csv(bool(0)) == "false"_expect); CHECK (format4Csv("Starship-3") == "\"Starship-3\""_expect ); // 3rd test today ;-) diff --git a/tests/vault/mem/engine-buffer-manager-test.cpp b/tests/vault/mem/engine-buffer-manager-test.cpp index b68563451..17b3b27a9 100644 --- a/tests/vault/mem/engine-buffer-manager-test.cpp +++ b/tests/vault/mem/engine-buffer-manager-test.cpp @@ -92,9 +92,9 @@ namespace test { CHECK (a2.siz > 555); // can use that memory without blowing up.... - auto doooh = new(a1.mem) f128{std::numeric_limits::max()}; + auto doooh = new(a1.mem) lflo{std::numeric_limits::max()}; *doooh /= 2; - CHECK (2 == std::numeric_limits::max() / *doooh); + CHECK (2 == std::numeric_limits::max() / *doooh); allo.deallocate (a1); allo.deallocate (a2);