[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
This commit is contained in:
peter klausler 2020-09-30 15:04:43 -07:00
parent d4e889f1f5
commit 4fb679d3b1
2 changed files with 6 additions and 6 deletions

View File

@ -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
}

View File

@ -97,7 +97,7 @@ int FormatControl<CONTEXT>::GetIntField(
}
int result{0};
bool negate{ch == '-'};
if (negate) {
if (negate || ch == '+') {
firstCh = '\0';
ch = PeekNext();
}