[flang-commits] [PATCH] D88610: Correct kP scaling on F output

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Sep 30 13:07:04 PDT 2020


klausler created this revision.
klausler added a reviewer: sscalpone.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

The sign of the scaling factor was misinterpreted for output
as meaning what it does for input.  To be correct, they
should cancel each other out.

print '(1P,F4 <https://reviews.llvm.org/F4>.3)', 1. ! printed 0.1 but should print 10.0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88610

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


Index: flang/unittests/Runtime/hello.cpp
===================================================================
--- flang/unittests/Runtime/hello.cpp
+++ flang/unittests/Runtime/hello.cpp
@@ -197,7 +197,7 @@
       {"(G32.17E4,';')", "        1.0000000000000000      ;"},
       {"(1P,E32.17,';')", "         1.00000000000000000E+00;"},
       {"(1PE32.17,';')", "         1.00000000000000000E+00;"}, // no comma
-      {"(1P,F32.17,';')", "             0.10000000000000000;"},
+      {"(1P,F32.17,';')", "            10.00000000000000000;"},
       {"(1P,G32.17,';')", "          1.0000000000000000    ;"},
       {"(ES32.17,';')", "         1.00000000000000000E+00;"},
       {"(2P,E32.17,';')", "         10.0000000000000000E-01;"},
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -278,8 +278,8 @@
       return EmitPrefix(edit, converted.length, editWidth) &&
           io_.Emit(converted.str, converted.length) && EmitSuffix(edit);
     }
-    int scale{IsZero() ? -1 : edit.modes.scale};
-    int expo{converted.decimalExponent - scale};
+    int scale{IsZero() ? 1 : edit.modes.scale}; // kP
+    int expo{converted.decimalExponent + scale};
     if (expo > extraDigits && extraDigits >= 0) {
       extraDigits = expo;
       if (!edit.digits.has_value()) { // F0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88610.295384.patch
Type: text/x-patch
Size: 1398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200930/a2113ec3/attachment.bin>


More information about the flang-commits mailing list