[flang-commits] [PATCH] D87653: [flang] Respect BZ mode in exponent parts, too

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Sep 14 17:03:55 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2cf572b5620: [flang] Respect BZ mode in exponent parts, too (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87653

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


Index: flang/unittests/Runtime/hello.cpp
===================================================================
--- flang/unittests/Runtime/hello.cpp
+++ flang/unittests/Runtime/hello.cpp
@@ -481,6 +481,7 @@
   realInTest("(-1P,F18.0)", "               125", 0x4093880000000000); // 1250
   realInTest("(1P,F18.0)", "               125", 0x4029000000000000); // 12.5
   realInTest("(BZ,F18.0)", "              125 ", 0x4093880000000000); // 1250
+  realInTest("(BZ,F18.0)", "       125 . e +1 ", 0x42a6bcc41e900000); // 1.25e13
   realInTest("(DC,F18.0)", "              12,5", 0x4029000000000000);
 
   listInputTest();
Index: flang/runtime/edit-input.cpp
===================================================================
--- flang/runtime/edit-input.cpp
+++ flang/runtime/edit-input.cpp
@@ -180,10 +180,11 @@
       first == 'E' || first == 'D' || first == 'Q') {
     Put('.'); // input field is normalized to a fraction
     auto start{got};
+    bool bzMode{(edit.modes.editingFlags & blankZero) != 0};
     for (; next; next = io.NextInField(remaining)) {
       char32_t ch{*next};
       if (ch == ' ' || ch == '\t') {
-        if (edit.modes.editingFlags & blankZero) {
+        if (bzMode) {
           ch = '0'; // BZ mode - treat blank as if it were zero
         } else {
           continue;
@@ -206,19 +207,29 @@
     if (next &&
         (*next == 'e' || *next == 'E' || *next == 'd' || *next == 'D' ||
             *next == 'q' || *next == 'Q')) {
+      // Optional exponent letter.  Blanks are allowed between the
+      // optional exponent letter and the exponent value.
       io.SkipSpaces(remaining);
       next = io.NextInField(remaining);
     }
-    exponent = -edit.modes.scale; // default exponent is -kP
+    // The default exponent is -kP, but the scale factor doesn't affect
+    // an explicit exponent.
+    exponent = -edit.modes.scale;
     if (next &&
-        (*next == '-' || *next == '+' || (*next >= '0' && *next <= '9'))) {
+        (*next == '-' || *next == '+' || (*next >= '0' && *next <= '9') ||
+            (bzMode && (*next == ' ' || *next == '\t')))) {
       bool negExpo{*next == '-'};
       if (negExpo || *next == '+') {
         next = io.NextInField(remaining);
       }
-      for (exponent = 0; next && (*next >= '0' && *next <= '9');
-           next = io.NextInField(remaining)) {
-        exponent = 10 * exponent + *next - '0';
+      for (exponent = 0; next; next = io.NextInField(remaining)) {
+        if (*next >= '0' && *next <= '9') {
+          exponent = 10 * exponent + *next - '0';
+        } else if (bzMode && (*next == ' ' || *next == '\t')) {
+          exponent = 10 * exponent;
+        } else {
+          break;
+        }
       }
       if (negExpo) {
         exponent = -exponent;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87653.291738.patch
Type: text/x-patch
Size: 2766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200915/1c9e3450/attachment-0001.bin>


More information about the flang-commits mailing list