[flang-commits] [PATCH] D88618: [flang] Fix Gw.d format output

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Sep 30 15:01:22 PDT 2020


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
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 estimation of the decimal exponent needs to allow for all
'd' of the requested significant digits.

Also accept a plus sign on a "+kP" scaling factor in a format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88618

Files:
  flang/runtime/edit-output.cpp
  flang/runtime/format-implementation.h


Index: flang/runtime/format-implementation.h
===================================================================
--- flang/runtime/format-implementation.h
+++ flang/runtime/format-implementation.h
@@ -97,7 +97,7 @@
   }
   int result{0};
   bool negate{ch == '-'};
-  if (negate) {
+  if (negate || ch == '+') {
     firstCh = '\0';
     ch = PeekNext();
   }
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -330,17 +330,17 @@
 template <int binaryPrecision>
 DataEdit RealOutputEditing<binaryPrecision>::EditForGOutput(DataEdit edit) {
   edit.descriptor = 'E';
-  if (!edit.width.has_value() ||
-      (*edit.width > 0 && edit.digits.value_or(-1) == 0)) {
+  int significantDigits{
+      edit.digits.value_or(BinaryFloatingPoint::decimalPrecision)}; // 'd'
+  if (!edit.width.has_value() || (*edit.width > 0 && significantDigits == 0)) {
     return edit; // Gw.0 -> Ew.0 for w > 0
   }
-  decimal::ConversionToDecimalResult converted{Convert(1, edit)};
+  decimal::ConversionToDecimalResult converted{
+      Convert(significantDigits, edit)};
   if (IsInfOrNaN(converted)) {
     return edit;
   }
   int expo{IsZero() ? 1 : converted.decimalExponent}; // 's'
-  int significantDigits{
-      edit.digits.value_or(BinaryFloatingPoint::decimalPrecision)}; // 'd'
   if (expo < 0 || expo > significantDigits) {
     return edit; // Ew.d
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88618.295420.patch
Type: text/x-patch
Size: 1473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200930/13f2dd17/attachment-0001.bin>


More information about the flang-commits mailing list