[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:
parent
d4e889f1f5
commit
4fb679d3b1
|
@ -330,17 +330,17 @@ bool RealOutputEditing<binaryPrecision>::EditFOutput(const DataEdit &edit) {
|
||||||
template <int binaryPrecision>
|
template <int binaryPrecision>
|
||||||
DataEdit RealOutputEditing<binaryPrecision>::EditForGOutput(DataEdit edit) {
|
DataEdit RealOutputEditing<binaryPrecision>::EditForGOutput(DataEdit edit) {
|
||||||
edit.descriptor = 'E';
|
edit.descriptor = 'E';
|
||||||
if (!edit.width.has_value() ||
|
int significantDigits{
|
||||||
(*edit.width > 0 && edit.digits.value_or(-1) == 0)) {
|
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
|
return edit; // Gw.0 -> Ew.0 for w > 0
|
||||||
}
|
}
|
||||||
decimal::ConversionToDecimalResult converted{Convert(1, edit)};
|
decimal::ConversionToDecimalResult converted{
|
||||||
|
Convert(significantDigits, edit)};
|
||||||
if (IsInfOrNaN(converted)) {
|
if (IsInfOrNaN(converted)) {
|
||||||
return edit;
|
return edit;
|
||||||
}
|
}
|
||||||
int expo{IsZero() ? 1 : converted.decimalExponent}; // 's'
|
int expo{IsZero() ? 1 : converted.decimalExponent}; // 's'
|
||||||
int significantDigits{
|
|
||||||
edit.digits.value_or(BinaryFloatingPoint::decimalPrecision)}; // 'd'
|
|
||||||
if (expo < 0 || expo > significantDigits) {
|
if (expo < 0 || expo > significantDigits) {
|
||||||
return edit; // Ew.d
|
return edit; // Ew.d
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ int FormatControl<CONTEXT>::GetIntField(
|
||||||
}
|
}
|
||||||
int result{0};
|
int result{0};
|
||||||
bool negate{ch == '-'};
|
bool negate{ch == '-'};
|
||||||
if (negate) {
|
if (negate || ch == '+') {
|
||||||
firstCh = '\0';
|
firstCh = '\0';
|
||||||
ch = PeekNext();
|
ch = PeekNext();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue