[flang-commits] [flang] 07cb4c0 - [flang] Make binary->decimal conversion buffer sizes accurate

peter klausler via flang-commits flang-commits at lists.llvm.org
Mon Oct 5 13:12:27 PDT 2020


Author: peter klausler
Date: 2020-10-05T13:11:58-07:00
New Revision: 07cb4c013c43721565530f3be077c947804da8a6

URL: https://github.com/llvm/llvm-project/commit/07cb4c013c43721565530f3be077c947804da8a6
DIFF: https://github.com/llvm/llvm-project/commit/07cb4c013c43721565530f3be077c947804da8a6.diff

LOG: [flang] Make binary->decimal conversion buffer sizes accurate

The binary values that produce the most significant decimal
digits in an exact conversion are those with the least normal
biased exponent (1) and all fractional bits set, not the
least-valued subnormals.  So the binary->decimal conversion
buffer sizes were a little short, and could cause a overrun crash.

Differential revision: https://reviews.llvm.org/D88688

Added: 
    

Modified: 
    flang/include/flang/Common/real.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/real.h b/flang/include/flang/Common/real.h
index eec29f1ca7b3..6ff9e441f2ce 100644
--- a/flang/include/flang/Common/real.h
+++ b/flang/include/flang/Common/real.h
@@ -39,26 +39,25 @@ static constexpr int BitsForBinaryPrecision(int binaryPrecision) {
   }
 }
 
-// Number of significant decimal digits in the fraction of the
-// exact conversion of the least nonzero (subnormal) value
-// in each type; i.e., a 128-bit quad value can be formatted
-// exactly with FORMAT(E0.22981).
+// Maximum number of significant decimal digits in the fraction of an
+// exact conversion in each type; computed by converting the value
+// with the minimum exponent (biased to 1) and all fractional bits set.
 static constexpr int MaxDecimalConversionDigits(int binaryPrecision) {
   switch (binaryPrecision) {
   case 8:
-    return 93;
+    return 96;
   case 11:
-    return 17;
+    return 21;
   case 24:
-    return 105;
+    return 112;
   case 53:
-    return 751;
+    return 767;
   case 64:
-    return 11495;
+    return 11514;
   case 106:
-    return 2 * 751;
+    return 2 * 767;
   case 113:
-    return 11530;
+    return 11563;
   default:
     return -1;
   }


        


More information about the flang-commits mailing list