[flang][runtime] Refine list-directed REAL(2) output

The rule used by list-directed REAL output editing to select
between Ew.d and Fw.d output editing breaks down for 16-bit
floating-point data, since the number of significant decimal
digits is so low that Ew,d output editing is nearly always selected.
Cap the test so that five-digit values will be output with Fw.d
editing.

Differential Revision: https://reviews.llvm.org/D129672
This commit is contained in:
Peter Klausler 2022-07-07 09:32:21 -07:00
parent 8b391cd908
commit faffcc3a46
1 changed files with 6 additions and 1 deletions

View File

@ -531,7 +531,12 @@ bool RealOutputEditing<binaryPrecision>::EditListDirectedOutput(
return EditEorDOutput(edit); return EditEorDOutput(edit);
} }
int expo{converted.decimalExponent}; int expo{converted.decimalExponent};
if (expo < 0 || expo > BinaryFloatingPoint::decimalPrecision) { // The decimal precision of 16-bit floating-point types is very low,
// so use a reasonable cap of 6 to allow more values to be emitted
// with Fw.d editing.
static constexpr int maxExpo{
std::max(6, BinaryFloatingPoint::decimalPrecision)};
if (expo < 0 || expo > maxExpo) {
DataEdit copy{edit}; DataEdit copy{edit};
copy.modes.scale = 1; // 1P copy.modes.scale = 1; // 1P
return EditEorDOutput(copy); return EditEorDOutput(copy);