[flang-commits] [flang] 724709e - [flang] Make F0.1 output editing of zero edge case consistent
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Apr 14 15:31:56 PDT 2022
Author: Peter Klausler
Date: 2022-04-14T15:31:47-07:00
New Revision: 724709e09ddcb4951a5f1c42238d3a8491424831
URL: https://github.com/llvm/llvm-project/commit/724709e09ddcb4951a5f1c42238d3a8491424831
DIFF: https://github.com/llvm/llvm-project/commit/724709e09ddcb4951a5f1c42238d3a8491424831.diff
LOG: [flang] Make F0.1 output editing of zero edge case consistent
The statement
PRINT '(2F0.1)', 0.0, 0.5
should emit consistent ".0 .5" output, not "0.0 .5".
Differential Revision: https://reviews.llvm.org/D123715
Added:
Modified:
flang/runtime/edit-output.cpp
flang/unittests/Runtime/NumericalFormatTest.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 824747ed17881..95292ded777b6 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -284,10 +284,13 @@ bool RealOutputEditing<binaryPrecision>::EditFOutput(const DataEdit &edit) {
return EmitPrefix(edit, converted.length, editWidth) &&
io_.Emit(converted.str, converted.length) && EmitSuffix(edit);
}
- int scale{IsZero() ? 1 : edit.modes.scale}; // kP
- int expo{converted.decimalExponent + scale};
+ int expo{converted.decimalExponent + edit.modes.scale /*kP*/};
int signLength{*converted.str == '-' || *converted.str == '+' ? 1 : 0};
int convertedDigits{static_cast<int>(converted.length) - signLength};
+ if (IsZero()) { // don't treat converted "0" as significant digit
+ expo = 0;
+ convertedDigits = 0;
+ }
int trailingOnes{0};
if (expo > extraDigits && extraDigits >= 0 && canIncrease) {
extraDigits = expo;
diff --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/flang/unittests/Runtime/NumericalFormatTest.cpp
index fd2183ff66419..3bc7b6dbf4221 100644
--- a/flang/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang/unittests/Runtime/NumericalFormatTest.cpp
@@ -333,6 +333,7 @@ TEST(IOApiTests, FormatDoubleValues) {
{
{"(E9.1,';')", " -0.0E+00;"},
{"(F4.0,';')", " -0.;"},
+ {"(F0.1,';')", "-.0;"},
{"(G8.0,';')", "-0.0E+00;"},
{"(G8.1,';')", " -0. ;"},
{"(G0,';')", "-0.;"},
@@ -649,6 +650,7 @@ TEST(IOApiTests, FormatDoubleValues) {
{"(F5.3,';')", -0.0005, "-.001;"},
{"(F5.3,';')", -0.00049999, "-.000;"},
{"(F5.3,';')", -0.000099999, "-.000;"},
+ {"(F0.1,';')", 0.0, ".0;"},
};
for (auto const &[format, value, expect] : individualTestCases) {
More information about the flang-commits
mailing list