Skip to content

Commit 567462b

Browse files
committed
[flang] Correct kP scaling on F output
The sign of the scaling factor was misinterpreted for output as meaning what it does for input. To be correct, they should cancel each other out. print '(1P,F4.3)', 1. ! printed 0.1 but should print 10.0 Differential revision: https://reviews.llvm.org/D88610
1 parent 5d6d8a2 commit 567462b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

flang/runtime/edit-output.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ bool RealOutputEditing<binaryPrecision>::EditFOutput(const DataEdit &edit) {
277277
return EmitPrefix(edit, converted.length, editWidth) &&
278278
io_.Emit(converted.str, converted.length) && EmitSuffix(edit);
279279
}
280-
int scale{IsZero() ? -1 : edit.modes.scale};
281-
int expo{converted.decimalExponent - scale};
280+
int scale{IsZero() ? 1 : edit.modes.scale}; // kP
281+
int expo{converted.decimalExponent + scale};
282282
if (expo > extraDigits && extraDigits >= 0) {
283283
extraDigits = expo;
284284
if (!edit.digits.has_value()) { // F0

flang/unittests/Runtime/hello.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int main() {
232232
{"(G32.17E4,';')", " 1.0000000000000000 ;"},
233233
{"(1P,E32.17,';')", " 1.00000000000000000E+00;"},
234234
{"(1PE32.17,';')", " 1.00000000000000000E+00;"}, // no comma
235-
{"(1P,F32.17,';')", " 0.10000000000000000;"},
235+
{"(1P,F32.17,';')", " 10.00000000000000000;"},
236236
{"(1P,G32.17,';')", " 1.0000000000000000 ;"},
237237
{"(ES32.17,';')", " 1.00000000000000000E+00;"},
238238
{"(2P,E32.17,';')", " 10.0000000000000000E-01;"},

0 commit comments

Comments
 (0)