Parameters: cover logarithmic scale conversions

this feature relies on the common logarithmic math,
yet with the additional twist that decibels need an additional factor of 10...
This commit is contained in:
Fischlurch 2026-09-21 02:07:44 +02:00
parent 4f8a8e8042
commit 0320c31eb5
3 changed files with 71 additions and 5 deletions

View file

@ -277,7 +277,7 @@ namespace par {
{ {
case NAT: return std::exp (WorkType(value)); case NAT: return std::exp (WorkType(value));
case BIN: return std::exp2 (WorkType(value)); case BIN: return std::exp2 (WorkType(value));
case DEC: return std::pow<WorkType> (10, value/10.0); case DEC: return std::pow (WorkType(10), WorkType(value/10.0));
default: default:
throw err::Logic{_Fmt{"Attempt to compute exponential " throw err::Logic{_Fmt{"Attempt to compute exponential "
"from a non-logarithmic value with metric %d"} "from a non-logarithmic value with metric %d"}

View file

@ -116,7 +116,7 @@ namespace test{
/** @test Scales can be configured to wrap cyclically, e.g. for angles. /** @test Scales can be configured to wrap cyclically, e.g. for angles.
* - demonstrate an unsigned angle scale with short precision * - demonstrate an unsigned angle scale with short precision
* - demonstrate a high-resolution scale symmetric to zero * - demonstrate a high-resolution scale symmetric to zero
* @todo WIP 9/26 ✔define ⟶ 🔁 implement * @todo WIP 9/26 ✔define ⟶ ✔ implement
*/ */
void void
verify_cyclicScale() verify_cyclicScale()
@ -158,7 +158,21 @@ namespace test{
/** @test Base value and data feeds from differing Scales can be joined together /** @test Base value and data feeds from differing Scales can be joined together
* @todo WIP 9/26 🔁 define ⟶ implement * - when the target scale defines limits (or is cyclic),
* this conforming is applied after all conversions
* - a feed can be marked as "factor", in which case
* the feed is multiplied to the target rather than added
* - even scales with integral type can carry log meaning
* - suitable intermediary types used for good precision,
* and especially to avoid wrapping signed into unsigned
* - the supported logarithmic flavours are accommodated,
* possibly converting the base of the logarithm accordingly
* - the factor 10 inherent to decibels is applied / removed
* before combining decibel values with other logarithms
* - applying a linear factor to a logarithmic scale is
* transformed into an addition in the logarithmic domain
* - adding a linear offset to a logarithmic scale is rejected
* @todo WIP 9/26 🔁 define ⟶ ✔ implement
*/ */
void void
verify_valueJoining() verify_valueJoining()
@ -183,6 +197,33 @@ namespace test{
// Note: number promotion rules of C++ would backfire nastily here... // Note: number promotion rules of C++ would backfire nastily here...
CHECK (short(-3) * uint64_t(2) > numeric_limits<int64_t>::max()); CHECK (short(-3) * uint64_t(2) > numeric_limits<int64_t>::max());
CHECK (short(-6) == sscale.join (-3, uint64_t(2), uscale)); CHECK (short(-6) == sscale.join (-3, uint64_t(2), uscale));
//---floating-point logarithmic scale conversions---
//
Scale<float> fscale = {.metric = NAT};
Scale<float> feed_dB = {.metric = DEC};
CHECK (roughEQ (fscale.join (0, float(20), feed_dB) , log(100.0f) )); // dB ⟼ natural logarithm; note 10dB ≙ factor 10 * lg(10) value divided / 10
fscale.metric = DEC;
CHECK (roughEQ (fscale.join (0, float(20), feed_dB) , 20.0f )); // dB ⟼ dB just passed-through and then added to value ≔ 0.0
feedScale.metric = BIN;
CHECK (roughEQ (fscale.join (0, int64_t(-3), feedScale), log10(1.0f/8)*10)); // binary log (given as int value) ⟼ dB
fscale.metric = LIN;
CHECK (roughEQ (fscale.join (1, int64_t(-3), feedScale), 1.0f/8 )); // binary log applied as factor to a linear scale
fscale.metric = BIN;
feedScale.metric = LIN;
feedScale.neutral = 1;
CHECK (feedScale.isFactor());
CHECK (fscale.isLogarithmic());
CHECK (1 + 3 == fscale.join (1, int64_t(8), feedScale)); // feed factor 8 ⟼ to binary logarithmic fscale (8 ≡ 2^3) and added there
feedScale.neutral = 0;
CHECK (not feedScale.isFactor());
VERIFY_FAIL ("adding a non-logarithmic data feed on top of a logarithmic base value"
, fscale.join (1, int64_t(8), feedScale));
} }

View file

@ -87251,8 +87251,8 @@ Prop.1: dist%3 1 2 0 1 2 0
<icon BUILTIN="button_ok"/> <icon BUILTIN="button_ok"/>
</node> </node>
</node> </node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1789172002831" ID="ID_939833813" MODIFIED="1789949264299" TEXT="gemische Scales handhaben"> <node COLOR="#338800" CREATED="1789172002831" ID="ID_939833813" MODIFIED="1789961933370" TEXT="gemische Scales handhaben">
<icon BUILTIN="pencil"/> <icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1789949153983" ID="ID_781783423" MODIFIED="1789949195612" TEXT="ushort-Scale mit Limits &#x27f5; kombiniert mit int64_t"> <node COLOR="#338800" CREATED="1789949153983" ID="ID_781783423" MODIFIED="1789949195612" TEXT="ushort-Scale mit Limits &#x27f5; kombiniert mit int64_t">
<icon BUILTIN="button_ok"/> <icon BUILTIN="button_ok"/>
</node> </node>
@ -87263,6 +87263,31 @@ Prop.1: dist%3 1 2 0 1 2 0
<arrowlink COLOR="#28b55c" DESTINATION="ID_1223578931" ENDARROW="Default" ENDINCLINATION="-139;1297;" ID="Arrow_ID_225645373" STARTARROW="None" STARTINCLINATION="111;6;"/> <arrowlink COLOR="#28b55c" DESTINATION="ID_1223578931" ENDARROW="Default" ENDINCLINATION="-139;1297;" ID="Arrow_ID_225645373" STARTARROW="None" STARTINCLINATION="111;6;"/>
<icon BUILTIN="button_ok"/> <icon BUILTIN="button_ok"/>
</node> </node>
<node COLOR="#338800" CREATED="1789961742643" ID="ID_949990390" MODIFIED="1789961760832" TEXT="Verbindung verschiedener log-Scales">
<icon BUILTIN="button_ok"/>
<node COLOR="#435e98" CREATED="1789961765581" ID="ID_1536983378" MODIFIED="1789961783683" TEXT="Umwandlung linear &#x27f7; log"/>
<node COLOR="#435e98" CREATED="1789961784810" ID="ID_245445484" MODIFIED="1789961910375" TEXT="Basis-Konvertierung logarithmischer werte"/>
<node COLOR="#435e98" CREATED="1789961796062" ID="ID_1145409092" MODIFIED="1789961910354" TEXT="spezieller Twist: in Decibels steckt ein Faktor 10">
<node CREATED="1789961817086" ID="ID_909916918" MODIFIED="1789961906542" TEXT="wenn als Input verwendet, mu&#xdf; der rausdividiert werden">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...und dieses Herausdividieren falte ich trickreich in den log-Basis-Konvertierungsfaktor.
</p>
<p>
&#220;berraschung: die Logarithmen-Matematik funktioniert ... aber das dumme Mensch braucht endlos um zu kapieren da&#223; die Beispielwerte stimmen
</p>
</body>
</html>
</richcontent>
</node>
<node CREATED="1789961831540" ID="ID_104579195" MODIFIED="1789961843094" TEXT="aber auf der Ergebnis-Seite mu&#xdf; er aufgeschlagen werden"/>
</node>
<node COLOR="#435e98" CREATED="1789961912393" ID="ID_1778190029" MODIFIED="1789961925432" TEXT="linearer Offset auf Logarithmus wird verweigert"/>
</node>
</node> </node>
</node> </node>
</node> </node>