From 4fb679d3b159f0a5e4ff87f4e7ecf44fbbf331b9 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Wed, 30 Sep 2020 15:04:43 -0700 Subject: [PATCH] [flang] Fix Gw.d format output 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. Differential revision: https://reviews.llvm.org/D88618 --- flang/runtime/edit-output.cpp | 10 +++++----- flang/runtime/format-implementation.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp index 4680c81..4d27cb6 100644 --- a/flang/runtime/edit-output.cpp +++ b/flang/runtime/edit-output.cpp @@ -330,17 +330,17 @@ bool RealOutputEditing::EditFOutput(const DataEdit &edit) { template DataEdit RealOutputEditing::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 } diff --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h index ad8bbcb..91d80a7 100644 --- a/flang/runtime/format-implementation.h +++ b/flang/runtime/format-implementation.h @@ -97,7 +97,7 @@ int FormatControl::GetIntField( } int result{0}; bool negate{ch == '-'}; - if (negate) { + if (negate || ch == '+') { firstCh = '\0'; ch = PeekNext(); } -- 2.7.4