lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 82b8907: Detect and repair decimal-precision


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 82b8907: Detect and repair decimal-precision inconsistencies in rate tables
Date: Thu, 15 Dec 2016 05:08:59 +0000 (UTC)

branch: master
commit 82b89079ffcdd3702b4c09b3c5455e4a7a3650e0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Detect and repair decimal-precision inconsistencies in rate tables
    
    The stated and implicit decimal precision defectively differ in some
    historical binary rate tables--see:
      http://lists.nongnu.org/archive/html/lmi/2016-12/msg00026.html
    This change detects such discrepancies, and fixes the worse kind
    (stated < implicit), which cause actual loss in conversion. It also
    flags the other kind, without fixing them. This revision is therefore
    useful for repairing defects in historical tables. Ultimately, after
    all such defects have been removed, the repair logic should be removed
    and any discrepancy should cause an exception to be thrown.
---
 rate_table.cpp |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/rate_table.cpp b/rate_table.cpp
index 04fe6a0..251a190 100644
--- a/rate_table.cpp
+++ b/rate_table.cpp
@@ -1857,6 +1857,38 @@ void table_impl::validate()
             fatal_error() << "Number of decimals not specified." << LMI_FLUSH;
             }
 
+        uint16_t putative_num_decimals = *num_decimals_;
+        uint16_t required_num_decimals = deduce_number_of_decimals(values_);
+        if(required_num_decimals < putative_num_decimals)
+            {
+            warning()
+                << "Table #" << *number_
+                << " specifies " << putative_num_decimals
+                << " decimals, but " << required_num_decimals
+                << " would suffice."
+                << LMI_FLUSH
+                ;
+            }
+        // Later, change '<' to '!=' to trim trailing zeros too (and expunge
+        // the warning above); but for now, adjust only for lost precision.
+        // This condition is true only if the table is defective,
+        // which should occur rarely enough that the cost of
+        // recalculating the hash value both here and below
+        // doesn't matter.
+        if(putative_num_decimals < required_num_decimals)
+            {
+            warning()
+                << "Table #" << *number_
+                << " specifies " << putative_num_decimals
+                << " decimals, but " << required_num_decimals
+                << " were necessary."
+                << "\nThis flaw has been corrected, and the CRC recalculated."
+                << LMI_FLUSH
+                ;
+            *num_decimals_ = required_num_decimals;
+            *hash_value_ = compute_hash_value();
+            }
+
         // If we don't have the hash, compute it ourselves. If we do, check
         // that it corresponds to what we should have unless the hash value in
         // input is just 0 which is equivalent to being not specified (such



reply via email to

[Prev in Thread] Current Thread [Next in Thread]