Просмотр исходного кода

Merge pull request #4145 from Apfelstruhdl/fix/checkdigitconsistency-double-precision

Fix checkDigitConsistency corrupting sub-digits of large readings
SybexXx 1 месяц назад
Родитель
Сommit
7e5a7869cf

+ 6 - 0
Changelog.md

@@ -1,3 +1,9 @@
+# [Unreleased]
+
+### Core Changes and Bug fixes
+- Fixed `checkDigitConsistency` corrupting the sub-digit part of large readings: it computed in `double` but returned `float`, so once a meter passed ~1,000,000 (7+ significant digits) the narrowing to 32-bit float mangled the decimals (e.g. a reading of `…691.67` was published as `…691.75`). The function now returns `double` and uses a `double` working variable throughout.
+
+
 # [16.1.0] - 2026-01-11
 
 For a full list of changes see [Full list of changes](https://github.com/jomjol/AI-on-the-edge-device/compare/v16.0.0...v16.1.0)

+ 4 - 4
code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -1107,11 +1107,11 @@ string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) {
     return input;
 }
 
-float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue) {
+double ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue) {
     int aktdigit, olddigit;
     int aktdigit_before, olddigit_before;
     int pot, pot_max;
-    float zw;
+    double zw;
     bool no_nulldurchgang = false;
 
     pot = _decilamshift;
@@ -1143,13 +1143,13 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams
 
         if (no_nulldurchgang) {
             if (aktdigit != olddigit) {
-                input = input + ((float) (olddigit - aktdigit)) * pow10_double(pot);     // New Digit is replaced by old Digit;
+                input = input + ((double)(olddigit - aktdigit)) * pow10_double(pot);     // New Digit is replaced by old Digit;
             }
         }
         else {
             // despite zero crossing, digit was not incremented --> add 1
             if (aktdigit == olddigit) {
-                input = input + ((float) (1)) * pow10_double(pot);   // add 1 at the point
+                input = input + ((double)(1)) * pow10_double(pot);   // add 1 at the point
             }
         }
 			

+ 1 - 1
code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h

@@ -30,7 +30,7 @@ protected:
     string ShiftDecimal(string in, int _decShift);
 
     string ErsetzteN(string, double _prevalue);
-    float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
+    double checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
 
     void InitNUMBERS();