[flang-commits] [PATCH] D123715: [flang] Make F0.1 output editing of zero edge case consistent

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Apr 14 15:32:05 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG724709e09ddc: [flang] Make F0.1 output editing of zero edge case consistent (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123715/new/

https://reviews.llvm.org/D123715

Files:
  flang/runtime/edit-output.cpp
  flang/unittests/Runtime/NumericalFormatTest.cpp


Index: flang/unittests/Runtime/NumericalFormatTest.cpp
===================================================================
--- flang/unittests/Runtime/NumericalFormatTest.cpp
+++ flang/unittests/Runtime/NumericalFormatTest.cpp
@@ -333,6 +333,7 @@
           {
               {"(E9.1,';')", " -0.0E+00;"},
               {"(F4.0,';')", " -0.;"},
+              {"(F0.1,';')", "-.0;"},
               {"(G8.0,';')", "-0.0E+00;"},
               {"(G8.1,';')", " -0.    ;"},
               {"(G0,';')", "-0.;"},
@@ -649,6 +650,7 @@
       {"(F5.3,';')", -0.0005, "-.001;"},
       {"(F5.3,';')", -0.00049999, "-.000;"},
       {"(F5.3,';')", -0.000099999, "-.000;"},
+      {"(F0.1,';')", 0.0, ".0;"},
   };
 
   for (auto const &[format, value, expect] : individualTestCases) {
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -284,10 +284,13 @@
       return EmitPrefix(edit, converted.length, editWidth) &&
           io_.Emit(converted.str, converted.length) && EmitSuffix(edit);
     }
-    int scale{IsZero() ? 1 : edit.modes.scale}; // kP
-    int expo{converted.decimalExponent + scale};
+    int expo{converted.decimalExponent + edit.modes.scale /*kP*/};
     int signLength{*converted.str == '-' || *converted.str == '+' ? 1 : 0};
     int convertedDigits{static_cast<int>(converted.length) - signLength};
+    if (IsZero()) { // don't treat converted "0" as significant digit
+      expo = 0;
+      convertedDigits = 0;
+    }
     int trailingOnes{0};
     if (expo > extraDigits && extraDigits >= 0 && canIncrease) {
       extraDigits = expo;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123715.422974.patch
Type: text/x-patch
Size: 1682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220414/4cb16d3f/attachment.bin>


More information about the flang-commits mailing list