[flang-commits] [flang] 4fb679d - [flang] Fix Gw.d format output
peter klausler via flang-commits
flang-commits at lists.llvm.org
Wed Sep 30 18:03:02 PDT 2020
Author: peter klausler
Date: 2020-09-30T18:02:25-07:00
New Revision: 4fb679d3b159f0a5e4ff87f4e7ecf44fbbf331b9
URL: https://github.com/llvm/llvm-project/commit/4fb679d3b159f0a5e4ff87f4e7ecf44fbbf331b9
DIFF: https://github.com/llvm/llvm-project/commit/4fb679d3b159f0a5e4ff87f4e7ecf44fbbf331b9.diff
LOG: [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
Added:
Modified:
flang/runtime/edit-output.cpp
flang/runtime/format-implementation.h
Removed:
################################################################################
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 4680c81129ed..4d27cb6320df 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -330,17 +330,17 @@ bool RealOutputEditing<binaryPrecision>::EditFOutput(const DataEdit &edit) {
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
}
diff --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h
index ad8bbcbcdcbd..91d80a733601 100644
--- a/flang/runtime/format-implementation.h
+++ b/flang/runtime/format-implementation.h
@@ -97,7 +97,7 @@ int FormatControl<CONTEXT>::GetIntField(
}
int result{0};
bool negate{ch == '-'};
- if (negate) {
+ if (negate || ch == '+') {
firstCh = '\0';
ch = PeekNext();
}
More information about the flang-commits
mailing list