diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp --- a/flang/runtime/edit-output.cpp +++ b/flang/runtime/edit-output.cpp @@ -284,10 +284,13 @@ 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(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 --- a/flang/unittests/Runtime/NumericalFormatTest.cpp +++ b/flang/unittests/Runtime/NumericalFormatTest.cpp @@ -333,6 +333,7 @@ { {"(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 @@ {"(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) {